11using System . Collections ;
2- using System . Linq . Expressions ;
3- using System . Reflection ;
42using System . Text ;
3+ using System . Reflection ;
4+ using System . Linq . Expressions ;
55
66namespace SQLiteSharp ;
77
8- public class TableQuery < T > ( SQLiteConnection connection , TableMap table ) : IEnumerable < T > , IEnumerable {
8+ public class TableQuery < T > ( SQLiteConnection connection , TableMap table ) : IEnumerable < T > , IEnumerable , IAsyncEnumerable < T > {
99 public SQLiteConnection Connection { get ; } = connection ;
1010 public TableMap Table { get ; } = table ;
1111
@@ -423,6 +423,10 @@ public IEnumerator<T> GetEnumerator() {
423423 IEnumerator IEnumerable . GetEnumerator ( ) {
424424 return GetEnumerator ( ) ;
425425 }
426+ /// <inheritdoc cref="GetEnumerator()"/>
427+ public IAsyncEnumerator < T > GetAsyncEnumerator ( CancellationToken cancelToken = default ) {
428+ return this . ToAsyncEnumerable ( ) . GetAsyncEnumerator ( cancelToken ) ;
429+ }
426430
427431 /// <summary>
428432 /// Returns a list of all the elements matching the query.
@@ -460,4 +464,45 @@ public T First(Expression<Func<T, bool>> predicate) {
460464 public T ? FirstOrDefault ( Expression < Func < T , bool > > predicate ) {
461465 return Where ( predicate ) . FirstOrDefault ( ) ;
462466 }
467+
468+ /// <inheritdoc cref="ToList()"/>
469+ public Task < List < T > > ToListAsync ( ) {
470+ return Task . Run ( ToList ) ;
471+ }
472+ /// <inheritdoc cref="ToArray()"/>
473+ public Task < T [ ] > ToArrayAsync ( ) {
474+ return Task . Run ( ToArray ) ;
475+ }
476+ /// <inheritdoc cref="Count()"/>
477+ public Task < int > CountAsync ( ) {
478+ return Task . Run ( Count ) ;
479+ }
480+ /// <inheritdoc cref="Count(Expression{Func{T, bool}})"/>
481+ public Task < int > CountAsync ( Expression < Func < T , bool > > predicate ) {
482+ return Task . Run ( ( ) => Count ( predicate ) ) ;
483+ }
484+ /// <inheritdoc cref="ElementAt(int)"/>
485+ public Task < T > ElementAtAsync ( int index ) {
486+ return Task . Run ( ( ) => ElementAt ( index ) ) ;
487+ }
488+ /// <inheritdoc cref="First()"/>
489+ public Task < T > FirstAsync ( ) {
490+ return Task . Run ( First ) ;
491+ }
492+ /// <inheritdoc cref="FirstOrDefault()"/>
493+ public Task < T ? > FirstOrDefaultAsync ( ) {
494+ return Task . Run ( FirstOrDefault ) ;
495+ }
496+ /// <inheritdoc cref="First(Expression{Func{T, bool}})"/>
497+ public Task < T > FirstAsync ( Expression < Func < T , bool > > predicate ) {
498+ return Task . Run ( ( ) => First ( predicate ) ) ;
499+ }
500+ /// <inheritdoc cref="FirstOrDefault(Expression{Func{T, bool}})"/>
501+ public Task < T ? > FirstOrDefaultAsync ( Expression < Func < T , bool > > predicate ) {
502+ return Task . Run ( ( ) => FirstOrDefault ( predicate ) ) ;
503+ }
504+ /// <inheritdoc cref="Delete(Expression{Func{T, bool}}?)"/>
505+ public Task < int > DeleteAsync ( Expression < Func < T , bool > > predicate ) {
506+ return Task . Run ( ( ) => Delete ( predicate ) ) ;
507+ }
463508}
0 commit comments