public static async Task <T> RunAndSingleAsync <T>(this IAsyncQueryRunner runner, string query, object parameters, Func <IRecord, T> operation) { var cursor = await runner.RunAsync(query, parameters); var result = await cursor.SingleAsync(operation); return(result); }
public static async Task <IResultSummary> RunAndConsumeAsync(this IAsyncQueryRunner runner, string query, object parameters = null) { var cursor = await runner.RunAsync(query, parameters); var summary = await cursor.ConsumeAsync(); return(summary); }
public static async Task <T> RunCachedAsync <T>(this IAsyncQueryRunner queryRunner, Query query, Func <IResultCursor, Task <T> > mapping, TimeSpan expirationTime = default, bool forceRefresh = false) { //Check if the query's result already has been cached. //If it is, it will grab the result from cache and return, //otherwise it will fetch the data from our database if (!cache.TryGet <T>(query, out T result) || forceRefresh) { //Execute the query against the database. var cursor = await queryRunner.RunAsync(query); //Map the binary result to result objects. result = await mapping(cursor); //Add the result objects to cache so next time //we can return the data from cache cache.AddToCache(query, result, expirationTime); } return(result); }