Beispiel #1
0
        public TResult ExecuteScalar <TResult>(PreparedCommand preparedCommand)
        {
            using var command = CreateCommand(preparedCommand);
            var result = command.ExecuteScalar();

            if (result == DBNull.Value)
            {
                return(default);
Beispiel #2
0
 public IEnumerable <TRecord> Stream <TRecord>(PreparedCommand command)
 {
     using var reader = ExecuteReader(command);
     foreach (var item in ProcessReader <TRecord>(reader, command))
     {
         yield return(item);
     }
 }
Beispiel #3
0
        public async IAsyncEnumerable <TRecord> StreamAsync <TRecord>(PreparedCommand command, [EnumeratorCancellation] CancellationToken cancellationToken = default)
        {
            await using var reader = await ExecuteReaderAsync(command, cancellationToken);

            await foreach (var result in ProcessReaderAsync <TRecord>(reader, command, cancellationToken))
            {
                yield return(result);
            }
        }
Beispiel #4
0
        public IEnumerable <TResult> Stream <TResult>(string query, CommandParameterValues args, Func <IProjectionMapper, TResult> projectionMapper, TimeSpan?commandTimeout = null)
        {
            var command = new PreparedCommand(query, args, RetriableOperation.Select, commandBehavior: CommandBehavior.Default, commandTimeout: commandTimeout);

            using var reader = ExecuteReader(command);
            var mapper = new ProjectionMapper(command, reader, configuration.ReaderStrategies);

            while (reader.Read())
            {
                yield return(projectionMapper(mapper));
            }
        }
Beispiel #5
0
        public async IAsyncEnumerable <TResult> StreamAsync <TResult>(string query, CommandParameterValues args, Func <IProjectionMapper, TResult> projectionMapper, TimeSpan?commandTimeout = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
        {
            var command = new PreparedCommand(query, args, RetriableOperation.Select, commandBehavior: CommandBehavior.Default, commandTimeout: commandTimeout);

            await using var reader = await ExecuteReaderAsync(command, cancellationToken);

            var mapper = new ProjectionMapper(command, reader, configuration.ReaderStrategies);

            while (await reader.ReadAsync(cancellationToken))
            {
                yield return(projectionMapper(mapper));
            }
        }
Beispiel #6
0
        IEnumerable <TRecord> ProcessReader <TRecord>(DbDataReader reader, PreparedCommand command)
        {
            using var timed = new TimedSection(ms => configuration.QueryLogger.ProcessReader(ms, name, command.Statement));
            var strategy = configuration.ReaderStrategies.Resolve <TRecord>(command);

            while (reader.Read())
            {
                var(instance, success) = strategy(reader);
                if (success)
                {
                    yield return(instance);
                }
            }
        }
Beispiel #7
0
 public async Task <int> ExecuteNonQueryAsync(PreparedCommand preparedCommand, CancellationToken cancellationToken = default)
 {
     using var command = CreateCommand(preparedCommand);
     return(await command.ExecuteNonQueryAsync(cancellationToken));
 }
Beispiel #8
0
 public int ExecuteNonQuery(PreparedCommand preparedCommand)
 {
     using var command = CreateCommand(preparedCommand);
     return(command.ExecuteNonQuery());
 }
Beispiel #9
0
        async IAsyncEnumerable <TRecord> ProcessReaderAsync <TRecord>(DbDataReader reader, PreparedCommand command, [EnumeratorCancellation] CancellationToken cancellationToken)
        {
            using var timed = new TimedSection(ms => configuration.QueryLogger.ProcessReader(ms, name, command.Statement));
            var strategy = configuration.ReaderStrategies.Resolve <TRecord>(command);

            while (await reader.ReadAsync(cancellationToken))
            {
                var(instance, success) = strategy(reader);
                if (success)
                {
                    yield return(instance);
                }
            }
        }
Beispiel #10
0
 public ProjectionMapper(PreparedCommand command, DbDataReader reader, IReaderStrategyRegistry readerStrategies)
 {
     this.command          = command;
     this.reader           = reader;
     this.readerStrategies = readerStrategies;
 }