diff --git a/src/cache.rs b/src/cache.rs index e728e6a..5c11608 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -64,7 +64,9 @@ fn establish_connection() -> Result { /// Read data from the cache, and return a vector of Cache. fn read_sql(connection: &mut PgConnection) -> QueryResult> { - let results = cache.filter(name.eq("Debian")).load::(connection)?; + let results = cache + // .filter(name.eq("Debian")) + .load::(connection)?; Ok(results) } @@ -82,16 +84,16 @@ fn insert_sql( ip: new_ip, }; - let results = diesel::insert_into(cache::table) + let result = diesel::insert_into(cache::table) .values(&cache_element) .get_result(connection)?; - Ok(results) + Ok(result) } /// SQL cache function to be called by `get_data` (read) and `api_client` (write). -pub fn sql_cache() { - let connection = &mut establish_connection().unwrap(); +pub fn sql_cache() -> Result<(), CacheError> { + let connection = &mut establish_connection()?; let data = match read_sql(connection) { Ok(data) => data, @@ -109,4 +111,6 @@ pub fn sql_cache() { } let new_cache_element = insert_sql(connection, "Arch", "archlinux.org", "95.217.163.246"); + + Ok(()) }