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

            if (result == DBNull.Value)
            {
                return(default);
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 7
0
 public async Task <int> ExecuteNonQueryAsync(PreparedCommand preparedCommand, CancellationToken cancellationToken = default)
 {
     using var command = CreateCommand(preparedCommand);
     return(await command.ExecuteNonQueryAsync(cancellationToken));
 }
Ejemplo n.º 8
0
 public int ExecuteNonQuery(PreparedCommand preparedCommand)
 {
     using var command = CreateCommand(preparedCommand);
     return(command.ExecuteNonQuery());
 }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 10
0
 public ProjectionMapper(PreparedCommand command, DbDataReader reader, IReaderStrategyRegistry readerStrategies)
 {
     this.command          = command;
     this.reader           = reader;
     this.readerStrategies = readerStrategies;
 }