Class SqlStatementObjectExtensions
- Namespace
- LfrlAnvil.Sql.Statements
- Assembly
- LfrlAnvil.Sql.Core.dll
Contains various extension methods related to SQL statements.
public static class SqlStatementObjectExtensions
- Inheritance
-
SqlStatementObjectExtensions
- Inherited Members
Methods
BeginTransactionAsync(IDbConnection, IsolationLevel, CancellationToken)
Asynchronously creates a new DbTransaction instance from the provided connection
.
[Pure]
public static ValueTask<DbTransaction> BeginTransactionAsync(this IDbConnection connection, IsolationLevel isolationLevel, CancellationToken cancellationToken = default)
Parameters
connection
IDbConnectionSource connection.
isolationLevel
IsolationLevelTransaction's IsolationLevel.
cancellationToken
CancellationTokenOptional CancellationToken.
Returns
- ValueTask<DbTransaction>
ValueTask<TResult> that returns a new DbTransaction instance.
Bind(SqlAsyncQueryReader, string)
Binds the provided SqlAsyncQueryReader to the given sql
.
[Pure]
public static SqlAsyncQueryReaderExecutor Bind(this SqlAsyncQueryReader reader, string sql)
Parameters
reader
SqlAsyncQueryReaderSource query reader.
sql
stringSQL to bind with.
Returns
- SqlAsyncQueryReaderExecutor
New SqlAsyncQueryReaderExecutor instance.
Bind(SqlAsyncScalarQueryReader, string)
Binds the provided SqlAsyncScalarQueryReader to the given sql
.
[Pure]
public static SqlAsyncScalarQueryReaderExecutor Bind(this SqlAsyncScalarQueryReader reader, string sql)
Parameters
reader
SqlAsyncScalarQueryReaderSource scalar query reader.
sql
stringSQL to bind with.
Returns
Bind(SqlParameterBinder, IEnumerable<SqlParameter>?)
Binds the provided SqlParameterBinder to the given parameter source
.
[Pure]
public static SqlParameterBinderExecutor Bind(this SqlParameterBinder binder, IEnumerable<SqlParameter>? source)
Parameters
binder
SqlParameterBinderSource parameter binder.
source
IEnumerable<SqlParameter>Parameter source to bind with.
Returns
- SqlParameterBinderExecutor
New SqlParameterBinderExecutor instance.
Bind(SqlQueryReader, string)
Binds the provided SqlQueryReader to the given sql
.
[Pure]
public static SqlQueryReaderExecutor Bind(this SqlQueryReader reader, string sql)
Parameters
reader
SqlQueryReaderSource query reader.
sql
stringSQL to bind with.
Returns
- SqlQueryReaderExecutor
New SqlQueryReaderExecutor instance.
Bind(SqlScalarQueryReader, string)
Binds the provided SqlScalarQueryReader to the given sql
.
[Pure]
public static SqlScalarQueryReaderExecutor Bind(this SqlScalarQueryReader reader, string sql)
Parameters
reader
SqlScalarQueryReaderSource scalar query reader.
sql
stringSQL to bind with.
Returns
- SqlScalarQueryReaderExecutor
New SqlScalarQueryReaderExecutor instance.
Bind<TRow>(SqlAsyncQueryReader<TRow>, string)
Binds the provided SqlAsyncQueryReader<TRow> to the given sql
.
[Pure]
public static SqlAsyncQueryReaderExecutor<TRow> Bind<TRow>(this SqlAsyncQueryReader<TRow> reader, string sql) where TRow : notnull
Parameters
reader
SqlAsyncQueryReader<TRow>Source query reader.
sql
stringSQL to bind with.
Returns
- SqlAsyncQueryReaderExecutor<TRow>
New SqlAsyncQueryReaderExecutor<TRow> instance.
Type Parameters
TRow
Row type.
Bind<T>(SqlAsyncScalarQueryReader<T>, string)
Binds the provided SqlAsyncScalarQueryReader<T> to the given sql
.
[Pure]
public static SqlAsyncScalarQueryReaderExecutor<T> Bind<T>(this SqlAsyncScalarQueryReader<T> reader, string sql)
Parameters
reader
SqlAsyncScalarQueryReader<T>Source scalar query reader.
sql
stringSQL to bind with.
Returns
- SqlAsyncScalarQueryReaderExecutor<T>
New SqlAsyncScalarQueryReaderExecutor<T> instance.
Type Parameters
T
Value type.
Bind<TSource>(SqlParameterBinder<TSource>, TSource?)
Binds the provided SqlParameterBinder<TSource> to the given parameter source
.
[Pure]
public static SqlParameterBinderExecutor<TSource> Bind<TSource>(this SqlParameterBinder<TSource> binder, TSource? source) where TSource : notnull
Parameters
binder
SqlParameterBinder<TSource>Source parameter binder.
source
TSourceParameter source to bind with.
Returns
- SqlParameterBinderExecutor<TSource>
New SqlParameterBinderExecutor<TSource> instance.
Type Parameters
TSource
Parameter source type.
Bind<TRow>(SqlQueryReader<TRow>, string)
Binds the provided SqlQueryReader<TRow> to the given sql
.
[Pure]
public static SqlQueryReaderExecutor<TRow> Bind<TRow>(this SqlQueryReader<TRow> reader, string sql) where TRow : notnull
Parameters
reader
SqlQueryReader<TRow>Source query reader.
sql
stringSQL to bind with.
Returns
- SqlQueryReaderExecutor<TRow>
New SqlQueryReaderExecutor<TRow> instance.
Type Parameters
TRow
Row type.
Bind<T>(SqlScalarQueryReader<T>, string)
Binds the provided SqlScalarQueryReader<T> to the given sql
.
[Pure]
public static SqlScalarQueryReaderExecutor<T> Bind<T>(this SqlScalarQueryReader<T> reader, string sql)
Parameters
reader
SqlScalarQueryReader<T>Source scalar query reader.
sql
stringSQL to bind with.
Returns
- SqlScalarQueryReaderExecutor<T>
New SqlScalarQueryReaderExecutor<T> instance.
Type Parameters
T
Value type.
CreateCommand(DbTransaction)
Creates a new DbCommand instance associated with the provided transaction
.
public static DbCommand CreateCommand(this DbTransaction transaction)
Parameters
transaction
DbTransactionSource transaction.
Returns
CreateCommand(IDbTransaction)
Creates a new IDbCommand instance associated with the provided transaction
.
public static IDbCommand CreateCommand(this IDbTransaction transaction)
Parameters
transaction
IDbTransactionSource transaction.
Returns
- IDbCommand
New IDbCommand instance.
Execute(IDbCommand)
Executes the provided command
.
public static int Execute(this IDbCommand command)
Parameters
command
IDbCommandSource command.
Returns
- int
The number of rows affected.
ExecuteAsync(IDbCommand, CancellationToken)
Asynchronously executes the provided command
.
public static ValueTask<int> ExecuteAsync(this IDbCommand command, CancellationToken cancellationToken = default)
Parameters
command
IDbCommandSource command.
cancellationToken
CancellationTokenOptional CancellationToken.
Returns
- ValueTask<int>
ValueTask<TResult> that returns the number of rows affected.
Multi(IDataReader)
Creates a new SqlMultiDataReader instance.
[Pure]
public static SqlMultiDataReader Multi(this IDataReader reader)
Parameters
reader
IDataReaderSource data reader.
Returns
- SqlMultiDataReader
New SqlMultiDataReader instance.
MultiAsync(IDataReader)
Creates a new SqlAsyncMultiDataReader instance.
[Pure]
public static SqlAsyncMultiDataReader MultiAsync(this IDataReader reader)
Parameters
reader
IDataReaderSource data reader.
Returns
- SqlAsyncMultiDataReader
New SqlAsyncMultiDataReader instance.
MultiQuery(IDbCommand)
Creates a new SqlMultiDataReader instance.
[Pure]
public static SqlMultiDataReader MultiQuery(this IDbCommand command)
Parameters
command
IDbCommandSource command.
Returns
- SqlMultiDataReader
New SqlMultiDataReader instance.
MultiQueryAsync(IDbCommand, CancellationToken)
Creates a new SqlAsyncMultiDataReader instance.
[Pure]
public static ValueTask<SqlAsyncMultiDataReader> MultiQueryAsync(this IDbCommand command, CancellationToken cancellationToken = default)
Parameters
command
IDbCommandSource command.
cancellationToken
CancellationTokenOptional CancellationToken.
Returns
- ValueTask<SqlAsyncMultiDataReader>
ValueTask<TResult> that returns a new SqlAsyncMultiDataReader instance.
Parameterize<TCommand>(TCommand, SqlParameterBinderExecutor)
Binds parameters to the provided command
.
public static TCommand Parameterize<TCommand>(this TCommand command, SqlParameterBinderExecutor executor) where TCommand : IDbCommand
Parameters
command
TCommandSource command.
executor
SqlParameterBinderExecutorSqlParameterBinderExecutor to use for binding.
Returns
- TCommand
command
.
Type Parameters
TCommand
DB command type.
Parameterize<TCommand, TSource>(TCommand, SqlParameterBinderExecutor<TSource>)
Binds parameters to the provided command
.
public static TCommand Parameterize<TCommand, TSource>(this TCommand command, SqlParameterBinderExecutor<TSource> executor) where TCommand : IDbCommand where TSource : notnull
Parameters
command
TCommandSource command.
executor
SqlParameterBinderExecutor<TSource>SqlParameterBinderExecutor<TSource> to use for binding.
Returns
- TCommand
command
.
Type Parameters
TCommand
DB command type.
TSource
Parameter source type.
Query(IDbCommand, SqlQueryReader, SqlQueryReaderOptions?)
Reads a collection of rows.
[Pure]
public static SqlQueryResult Query(this IDbCommand command, SqlQueryReader reader, SqlQueryReaderOptions? options = null)
Parameters
command
IDbCommandSource command.
reader
SqlQueryReaderSqlQueryReader to use for reading.
options
SqlQueryReaderOptions?Query reader options.
Returns
- SqlQueryResult
Returns a collection of read rows.
Query(IDbCommand, SqlQueryReaderExecutor, SqlQueryReaderOptions?)
Reads a collection of rows.
[Pure]
public static SqlQueryResult Query(this IDbCommand command, SqlQueryReaderExecutor executor, SqlQueryReaderOptions? options = null)
Parameters
command
IDbCommandSource command.
executor
SqlQueryReaderExecutorSqlQueryReaderExecutor to use for reading.
options
SqlQueryReaderOptions?Query reader options.
Returns
- SqlQueryResult
Returns a collection of read rows.
Query(IDbCommand, SqlScalarQueryReader)
Reads a scalar value.
[Pure]
public static SqlScalarQueryResult Query(this IDbCommand command, SqlScalarQueryReader reader)
Parameters
command
IDbCommandSource command.
reader
SqlScalarQueryReaderSqlScalarQueryReader to use for reading.
Returns
- SqlScalarQueryResult
Returns a read scalar value.
Query(IDbCommand, SqlScalarQueryReaderExecutor)
Reads a scalar value.
[Pure]
public static SqlScalarQueryResult Query(this IDbCommand command, SqlScalarQueryReaderExecutor executor)
Parameters
command
IDbCommandSource command.
executor
SqlScalarQueryReaderExecutorSqlScalarQueryReaderExecutor to use for reading.
Returns
- SqlScalarQueryResult
Returns a read scalar value.
QueryAsync(IDbCommand, SqlAsyncQueryReader, SqlQueryReaderOptions?, CancellationToken)
Asynchronously reads a collection of rows.
[Pure]
public static ValueTask<SqlQueryResult> QueryAsync(this IDbCommand command, SqlAsyncQueryReader reader, SqlQueryReaderOptions? options = null, CancellationToken cancellationToken = default)
Parameters
command
IDbCommandSource command.
reader
SqlAsyncQueryReaderSqlAsyncQueryReader to use for reading.
options
SqlQueryReaderOptions?Query reader options.
cancellationToken
CancellationTokenOptional CancellationToken.
Returns
- ValueTask<SqlQueryResult>
ValueTask<TResult> that returns a collection of read rows.
QueryAsync(IDbCommand, SqlAsyncQueryReaderExecutor, SqlQueryReaderOptions?, CancellationToken)
Asynchronously reads a collection of rows.
[Pure]
public static ValueTask<SqlQueryResult> QueryAsync(this IDbCommand command, SqlAsyncQueryReaderExecutor executor, SqlQueryReaderOptions? options = null, CancellationToken cancellationToken = default)
Parameters
command
IDbCommandSource command.
executor
SqlAsyncQueryReaderExecutorSqlAsyncQueryReaderExecutor to use for reading.
options
SqlQueryReaderOptions?Query reader options.
cancellationToken
CancellationTokenOptional CancellationToken.
Returns
- ValueTask<SqlQueryResult>
ValueTask<TResult> that returns a collection of read rows.
QueryAsync(IDbCommand, SqlAsyncScalarQueryReader, CancellationToken)
Asynchronously reads a scalar value.
[Pure]
public static ValueTask<SqlScalarQueryResult> QueryAsync(this IDbCommand command, SqlAsyncScalarQueryReader reader, CancellationToken cancellationToken = default)
Parameters
command
IDbCommandSource command.
reader
SqlAsyncScalarQueryReaderSqlAsyncScalarQueryReader to use for reading.
cancellationToken
CancellationTokenOptional CancellationToken.
Returns
- ValueTask<SqlScalarQueryResult>
ValueTask<TResult> that returns a read scalar value.
QueryAsync(IDbCommand, SqlAsyncScalarQueryReaderExecutor, CancellationToken)
Asynchronously reads a scalar value.
[Pure]
public static ValueTask<SqlScalarQueryResult> QueryAsync(this IDbCommand command, SqlAsyncScalarQueryReaderExecutor executor, CancellationToken cancellationToken = default)
Parameters
command
IDbCommandSource command.
executor
SqlAsyncScalarQueryReaderExecutorSqlAsyncScalarQueryReaderExecutor to use for reading.
cancellationToken
CancellationTokenOptional CancellationToken.
Returns
- ValueTask<SqlScalarQueryResult>
ValueTask<TResult> that returns a read scalar value.
QueryAsync<TRow>(IDbCommand, SqlAsyncQueryReaderExecutor<TRow>, SqlQueryReaderOptions?, CancellationToken)
Asynchronously reads a collection of rows.
[Pure]
public static ValueTask<SqlQueryResult<TRow>> QueryAsync<TRow>(this IDbCommand command, SqlAsyncQueryReaderExecutor<TRow> executor, SqlQueryReaderOptions? options = null, CancellationToken cancellationToken = default) where TRow : notnull
Parameters
command
IDbCommandSource command.
executor
SqlAsyncQueryReaderExecutor<TRow>SqlAsyncQueryReaderExecutor<TRow> to use for reading.
options
SqlQueryReaderOptions?Query reader options.
cancellationToken
CancellationTokenOptional CancellationToken.
Returns
- ValueTask<SqlQueryResult<TRow>>
ValueTask<TResult> that returns a collection of read rows.
Type Parameters
TRow
Row type.
QueryAsync<TRow>(IDbCommand, SqlAsyncQueryReader<TRow>, SqlQueryReaderOptions?, CancellationToken)
Asynchronously reads a collection of rows.
[Pure]
public static ValueTask<SqlQueryResult<TRow>> QueryAsync<TRow>(this IDbCommand command, SqlAsyncQueryReader<TRow> reader, SqlQueryReaderOptions? options = null, CancellationToken cancellationToken = default) where TRow : notnull
Parameters
command
IDbCommandSource command.
reader
SqlAsyncQueryReader<TRow>SqlAsyncQueryReader<TRow> to use for reading.
options
SqlQueryReaderOptions?Query reader options.
cancellationToken
CancellationTokenOptional CancellationToken.
Returns
- ValueTask<SqlQueryResult<TRow>>
ValueTask<TResult> that returns a collection of read rows.
Type Parameters
TRow
Row type.
QueryAsync<T>(IDbCommand, SqlAsyncScalarQueryReaderExecutor<T>, CancellationToken)
Asynchronously reads a scalar value.
[Pure]
public static ValueTask<SqlScalarQueryResult<T>> QueryAsync<T>(this IDbCommand command, SqlAsyncScalarQueryReaderExecutor<T> executor, CancellationToken cancellationToken = default)
Parameters
command
IDbCommandSource command.
executor
SqlAsyncScalarQueryReaderExecutor<T>SqlAsyncScalarQueryReaderExecutor<T> to use for reading.
cancellationToken
CancellationTokenOptional CancellationToken.
Returns
- ValueTask<SqlScalarQueryResult<T>>
ValueTask<TResult> that returns a read scalar value.
Type Parameters
T
Value type.
QueryAsync<T>(IDbCommand, SqlAsyncScalarQueryReader<T>, CancellationToken)
Asynchronously reads a scalar value.
[Pure]
public static ValueTask<SqlScalarQueryResult<T>> QueryAsync<T>(this IDbCommand command, SqlAsyncScalarQueryReader<T> reader, CancellationToken cancellationToken = default)
Parameters
command
IDbCommandSource command.
reader
SqlAsyncScalarQueryReader<T>SqlAsyncScalarQueryReader<T> to use for reading.
cancellationToken
CancellationTokenOptional CancellationToken.
Returns
- ValueTask<SqlScalarQueryResult<T>>
ValueTask<TResult> that returns a read scalar value.
Type Parameters
T
Value type.
Query<TRow>(IDbCommand, SqlQueryReaderExecutor<TRow>, SqlQueryReaderOptions?)
Reads a collection of rows.
[Pure]
public static SqlQueryResult<TRow> Query<TRow>(this IDbCommand command, SqlQueryReaderExecutor<TRow> executor, SqlQueryReaderOptions? options = null) where TRow : notnull
Parameters
command
IDbCommandSource command.
executor
SqlQueryReaderExecutor<TRow>SqlQueryReaderExecutor<TRow> to use for reading.
options
SqlQueryReaderOptions?Query reader options.
Returns
- SqlQueryResult<TRow>
Returns a collection of read rows.
Type Parameters
TRow
Row type.
Query<TRow>(IDbCommand, SqlQueryReader<TRow>, SqlQueryReaderOptions?)
Reads a collection of rows.
[Pure]
public static SqlQueryResult<TRow> Query<TRow>(this IDbCommand command, SqlQueryReader<TRow> reader, SqlQueryReaderOptions? options = null) where TRow : notnull
Parameters
command
IDbCommandSource command.
reader
SqlQueryReader<TRow>SqlQueryReader<TRow> to use for reading.
options
SqlQueryReaderOptions?Query reader options.
Returns
- SqlQueryResult<TRow>
Returns a collection of read rows.
Type Parameters
TRow
Row type.
Query<T>(IDbCommand, SqlScalarQueryReaderExecutor<T>)
Reads a scalar value.
[Pure]
public static SqlScalarQueryResult<T> Query<T>(this IDbCommand command, SqlScalarQueryReaderExecutor<T> executor)
Parameters
command
IDbCommandSource command.
executor
SqlScalarQueryReaderExecutor<T>SqlScalarQueryReaderExecutor<T> to use for reading.
Returns
- SqlScalarQueryResult<T>
Returns a read scalar value.
Type Parameters
T
Value type.
Query<T>(IDbCommand, SqlScalarQueryReader<T>)
Reads a scalar value.
[Pure]
public static SqlScalarQueryResult<T> Query<T>(this IDbCommand command, SqlScalarQueryReader<T> reader)
Parameters
command
IDbCommandSource command.
reader
SqlScalarQueryReader<T>SqlScalarQueryReader<T> to use for reading.
Returns
- SqlScalarQueryResult<T>
Returns a read scalar value.
Type Parameters
T
Value type.
SetText<TCommand>(TCommand, string)
Updates the CommandText of the provided command
.
public static TCommand SetText<TCommand>(this TCommand command, string sql) where TCommand : IDbCommand
Parameters
command
TCommandSource command.
sql
stringValue to set.
Returns
- TCommand
command
.
Type Parameters
TCommand
DB command type.
SetTimeout<TCommand>(TCommand, TimeSpan)
Updates the CommandTimeout of the provided command
.
public static TCommand SetTimeout<TCommand>(this TCommand command, TimeSpan timeout) where TCommand : IDbCommand
Parameters
command
TCommandSource command.
timeout
TimeSpanValue to set.
Returns
- TCommand
command
.
Type Parameters
TCommand
DB command type.
Exceptions
- ArgumentException
When
timeout
is less 0.