Exemple #1
0
 public static Task Query(this ISqDatabase database, IExprQuery query, Action <ISqDataRecordReader> handler)
 {
     return(database.Query <object?>(query,
                                     null,
                                     (acc, r) =>
     {
         handler(r);
         return acc;
     }));
 }
Exemple #2
0
 public static Task Query(this ISqDatabase database, IExprQuery query, Func <ISqDataRecordReader, Task> handler)
 {
     return(database.Query <object?>(query,
                                     null,
                                     async(acc, r) =>
     {
         await handler(r);
         return acc;
     }));
 }
Exemple #3
0
 public static Task <List <T> > QueryList <T>(this ISqDatabase database, IExprQuery expr, Func <ISqDataRecordReader, T> factory, Predicate <T>?predicateItem = null)
 {
     return(database.Query(expr,
                           new List <T>(),
                           (acc, record) =>
     {
         var item = factory(record);
         if (predicateItem != null)
         {
             if (!predicateItem(item))
             {
                 return acc;
             }
         }
         acc.Add(item);
         return acc;
     }));
 }
Exemple #4
0
        public static Task <Dictionary <TKey, TValue> > QueryDictionary <TKey, TValue>(
            this ISqDatabase database,
            IExprQuery expr,
            Func <ISqDataRecordReader, TKey> keyFactory,
            Func <ISqDataRecordReader, TValue> valueFactory,
            KeyDuplicationHandler <TKey, TValue>?keyDuplicationHandler = null,
            Func <TKey, TValue, bool>?predicate = null)
            where TKey : notnull
        {
            return(database.Query(expr,
                                  new Dictionary <TKey, TValue>(),
                                  (acc, record) =>
            {
                var key = keyFactory(record);
                var value = valueFactory(record);

                if (predicate != null && !predicate(key, value))
                {
                    return acc;
                }

                if (keyDuplicationHandler == null)
                {
                    acc.Add(key, value);
                }
                else
                {
                    if (acc.TryGetValue(key, out var oldValue))
                    {
                        keyDuplicationHandler(key, oldValue, value, acc);
                    }
                    else
                    {
                        acc.Add(key, value);
                    }
                }
                return acc;
            }));
        }
 public static Task Query(this IExprQueryFinal query, ISqDatabase database, Action <ISqDataRecordReader> handler)
 => database.Query(query.Done(), handler);
 public static Task <TAgg> Query <TAgg>(this IExprQueryFinal query, ISqDatabase database, TAgg seed, Func <TAgg, ISqDataRecordReader, TAgg> aggregator)
 => database.Query(query.Done(), seed, aggregator);
Exemple #7
0
 public static Task Query(this IExprQuery query, ISqDatabase database, Func <ISqDataRecordReader, Task> handler)
 => database.Query(query, handler);