Interface IRedbContext

Namespace: redb.Core.Data
Assembly: redb.Core.dll

Main database context interface for REDB.
Facade over connection, key generator, and bulk operations.
Replaces EF Core DbContext.

public interface IRedbContext : IAsyncDisposable, IDisposable

Properties

Bulk

Bulk operations (COPY protocol).

IBulkOperations Bulk { get; }

CurrentTransaction

Current active transaction (null if none).

IRedbTransaction? CurrentTransaction { get; }

Db

Database connection for queries and commands.

IRedbConnection Db { get; }

IsDisposed

True once the context has been disposed - the scope that owned it has ended (V4, review).

bool IsDisposed { get; }

IsInTransaction

Whether any transaction is active — explicit (CurrentTransaction) or ambient (TransactionScope).

bool IsInTransaction { get; }

Keys

Key generator with caching.

IKeyGenerator Keys { get; }

Methods

BeginTransactionAsync()

Begin new transaction.

Task<IRedbTransaction> BeginTransactionAsync()

BeginTransactionAsync(IsolationLevel?, CancellationToken)

Begin new transaction.

Task<IRedbTransaction> BeginTransactionAsync(IsolationLevel? isolationLevel = null, CancellationToken cancellationToken = default)

Execute(string, params object[])

Synchronous on the calling thread.

int Execute(string sql, params object[] parameters)

ExecuteAsync(string, object[], CancellationToken)

Cancellable form.

Task<int> ExecuteAsync(string sql, object[] parameters, CancellationToken cancellationToken)

ExecuteAsync(string, params object[])

Execute SQL command (INSERT, UPDATE, DELETE).

Task<int> ExecuteAsync(string sql, params object[] parameters)

ExecuteAtomicAsync(Func<Task>, CancellationToken)

Execute operations atomically (all-or-nothing).

Task ExecuteAtomicAsync(Func<Task> operations, CancellationToken cancellationToken = default)

ExecuteAtomicAsync(Func<Task>)

Execute operations atomically (all-or-nothing).

Task ExecuteAtomicAsync(Func<Task> operations)

ExecuteAtomicAsync(IsolationLevel, Func<Task>, CancellationToken)

Atomic execution under an explicit isolation level (BR-1). An active or ambient transaction

Task ExecuteAtomicAsync(IsolationLevel isolationLevel, Func<Task> operations, CancellationToken cancellationToken = default)

ExecuteAtomicAsync<T>(Func<Task<T>>, CancellationToken)

Execute operations atomically and return result.

Task<T> ExecuteAtomicAsync<T>(Func<Task<T>> operations, CancellationToken cancellationToken = default)

ExecuteAtomicAsync<T>(Func<Task<T>>)

Execute operations atomically and return result.

Task<T> ExecuteAtomicAsync<T>(Func<Task<T>> operations)

ExecuteAtomicAsync<T>(IsolationLevel, Func<Task<T>>, CancellationToken)

Result-returning form of the isolation-level overload (BR-1).

Task<T> ExecuteAtomicAsync<T>(IsolationLevel isolationLevel, Func<Task<T>> operations, CancellationToken cancellationToken = default)

ExecuteJson(string, params object[])

Synchronous on the calling thread.

string? ExecuteJson(string sql, params object[] parameters)

ExecuteJsonAsync(string, object[], CancellationToken)

Cancellable form.

Task<string?> ExecuteJsonAsync(string sql, object[] parameters, CancellationToken cancellationToken)

ExecuteJsonAsync(string, params object[])

Execute SQL returning JSON.

Task<string?> ExecuteJsonAsync(string sql, params object[] parameters)

ExecuteJsonListAsync(string, object[], CancellationToken)

Cancellable form.

Task<List<string>> ExecuteJsonListAsync(string sql, object[] parameters, CancellationToken cancellationToken)

ExecuteJsonListAsync(string, params object[])

Execute SQL returning multiple JSON rows.

Task<List<string>> ExecuteJsonListAsync(string sql, params object[] parameters)

ExecuteScalar<T>(string, params object[])

Synchronous on the calling thread.

T? ExecuteScalar<T>(string sql, params object[] parameters)

ExecuteScalarAsync<T>(string, object[], CancellationToken)

Cancellable form.

Task<T?> ExecuteScalarAsync<T>(string sql, object[] parameters, CancellationToken cancellationToken)

ExecuteScalarAsync<T>(string, params object[])

Execute SQL query and return scalar value.

Task<T?> ExecuteScalarAsync<T>(string sql, params object[] parameters)

NextObjectIdAsync()

Get next object ID.

Task<long> NextObjectIdAsync()

NextObjectIdAsync(CancellationToken)

Get next object ID.

Task<long> NextObjectIdAsync(CancellationToken cancellationToken = default)

NextObjectIdBatchAsync(int, CancellationToken)

Get batch of object IDs.

Task<long[]> NextObjectIdBatchAsync(int count, CancellationToken cancellationToken = default)

NextObjectIdBatchAsync(int)

Get batch of object IDs.

Task<long[]> NextObjectIdBatchAsync(int count)

NextValueIdAsync()

Get next value ID.

Task<long> NextValueIdAsync()

NextValueIdAsync(CancellationToken)

Get next value ID.

Task<long> NextValueIdAsync(CancellationToken cancellationToken = default)

NextValueIdBatchAsync(int, CancellationToken)

Get batch of value IDs.

Task<long[]> NextValueIdBatchAsync(int count, CancellationToken cancellationToken = default)

NextValueIdBatchAsync(int)

Get batch of value IDs.

Task<long[]> NextValueIdBatchAsync(int count)

Query<T>(string, params object[])

Synchronous on the calling thread.

List<T> Query<T>(string sql, params object[] parameters) where T : new()

QueryAsync<T>(string, object[], CancellationToken)

Cancellable form: parameters as an explicit array (params cannot precede ct).

Task<List<T>> QueryAsync<T>(string sql, object[] parameters, CancellationToken cancellationToken) where T : new()

QueryAsync<T>(string, params object[])

Execute SQL query and return list of mapped objects.

Task<List<T>> QueryAsync<T>(string sql, params object[] parameters) where T : new()

QueryFirstOrDefault<T>(string, params object[])

Synchronous on the calling thread.

T? QueryFirstOrDefault<T>(string sql, params object[] parameters) where T : class, new()

QueryFirstOrDefaultAsync<T>(string, object[], CancellationToken)

Cancellable form.

Task<T?> QueryFirstOrDefaultAsync<T>(string sql, object[] parameters, CancellationToken cancellationToken) where T : class, new()

QueryFirstOrDefaultAsync<T>(string, params object[])

Execute SQL query and return first result or null.

Task<T?> QueryFirstOrDefaultAsync<T>(string sql, params object[] parameters) where T : class, new()

QueryRowsAsJsonAsync(string, object[], CancellationToken)

The rows of sql as a JSON array of objects keyed by column name, NULL values included;

Task<string> QueryRowsAsJsonAsync(string sql, object[] parameters, CancellationToken cancellationToken = default)

QueryScalarListAsync<T>(string, object[], CancellationToken)

Cancellable form.

Task<List<T>> QueryScalarListAsync<T>(string sql, object[] parameters, CancellationToken cancellationToken)

QueryScalarListAsync<T>(string, params object[])

Execute SQL query and return list of scalar values (first column only).

Task<List<T>> QueryScalarListAsync<T>(string sql, params object[] parameters)