public async Task <dynamic> InsertAsync <T>(T entity, IDbConnection connection = null, IDbTransaction transaction = null) where T : class { if (connection == null) { using (connection = await _factory.CreateAsync()) { return(await connection.InsertAsync(entity, transaction : transaction)); } } else { return(await connection.InsertAsync(entity, transaction : transaction)); } }
private async Task InitConnection(CancellationToken cancellationToken) { mConnection?.Dispose(); mConnection = await mConnectionFactory.CreateAsync(cancellationToken) .ConfigureAwait(false); }
public async Task <T> ExecuteQueryAsync <T>(IQuery query, Func <NpgsqlCommand, Task <T> > functionAsync) { if (query == null) { throw new ArgumentNullException(nameof(query)); } if (functionAsync == null) { throw new ArgumentNullException(nameof(functionAsync)); } using (var connection = await connectionFactory.CreateAsync()) { using (var command = connection.CreateCommand()) { commandPreparer.Prepare(command, query); try { return(await functionAsync(command)); } catch (PostgresException pe) { if (pe.SqlState == "23505") { throw new UniqueIndexViolationException(pe); } throw; } } } }
/// <inheritdoc/> public async Task <T> GetAsync <T>(string sql, object param = null, IDbConnection connection = null, IDbTransaction transaction = null) { if (connection == null) { using (connection = await _factory.CreateAsync()) { return(await connection.QueryFirstOrDefaultAsync <T>(sql, param, commandTimeout : _commandTimeout)); } } else { return(await connection.QueryFirstOrDefaultAsync <T>(sql, param, transaction, commandTimeout : _commandTimeout)); } }
public async Task <IEnumerable <T> > GetAllAsync <T>(ISqlObject obj, IDbConnection connection = null, IDbTransaction transaction = null) { if (connection == null) { using (connection = await _factory.CreateAsync()) { return(await connection.QueryAsync <T>(obj.Sql, obj.QueryParams, commandTimeout : _commandTimeout)); } } else { return(await connection.QueryAsync <T>(obj.Sql, obj.QueryParams, transaction, commandTimeout : _commandTimeout)); } }