using System.Data; using System.Data.Common; using System.Runtime.CompilerServices; using Dapper; using FruityFoundation.DataAccess.Abstractions; using Microsoft.Data.Sqlite; namespace FruityFoundation.DataAccess.Sqlite; // ReSharper disable once UnusedTypeParameter public class NonTransactionalDbConnection : SqliteConnection, INonTransactionalDbConnection where TConnectionType : ConnectionType { /// /// C'tor /// public NonTransactionalDbConnection(string connectionString) : base(connectionString) { } /// public async Task> Query( string sql, object? param = null, CancellationToken cancellationToken = default ) => await this.QueryAsync(new CommandDefinition(sql, param, cancellationToken: cancellationToken)); /// public async IAsyncEnumerable QueryUnbuffered( string sql, object? param = null, [EnumeratorCancellation] CancellationToken cancellationToken = default ) { var query = this.QueryUnbufferedAsync(sql, param, transaction: null) .WithCancellation(cancellationToken); await foreach (var item in query) yield return item; } /// public async Task QuerySingle( string sql, object? param = null, CancellationToken cancellationToken = default ) => await this.QuerySingleAsync(new CommandDefinition(sql, param, cancellationToken: cancellationToken)); /// public async Task Execute( string sql, object? param = null, CancellationToken cancellationToken = default ) => await this.ExecuteAsync(new CommandDefinition(sql, param, cancellationToken: cancellationToken)); /// public async Task ExecuteScalar( string sql, object? param = null, CancellationToken cancellationToken = default ) => await this.ExecuteScalarAsync(new CommandDefinition(sql, param, cancellationToken: cancellationToken)); /// public async Task ExecuteReader( string sql, object? param = null, CancellationToken cancellationToken = default ) => await this.ExecuteReaderAsync(new CommandDefinition(sql, param, cancellationToken: cancellationToken)); /// public async Task> CreateTransaction() { if (!State.HasFlag(ConnectionState.Open)) await OpenAsync(); var tx = BeginTransaction(); return new DbTransaction(tx); } /// public async Task> CreateTransaction(IsolationLevel isolationLevel) { if (!State.HasFlag(ConnectionState.Open)) await OpenAsync(); var tx = BeginTransaction(isolationLevel); return new DbTransaction(tx); } /// public async Task> CreateTransaction(IsolationLevel isolationLevel, bool deferred) { if (!State.HasFlag(ConnectionState.Open)) await OpenAsync(); var tx = BeginTransaction(isolationLevel, deferred); return new DbTransaction(tx); } }