FdbDatabaseProviderExtensions
Namespace: FoundationDB.Client · class
Methods
AsDatabaseProvider
static IFdbDatabaseScopeProvider AsDatabaseProvider(IFdbDatabase db, CancellationToken lifetime = null)
Convert this database instance into a provider
db— Database singleton to wrap into a providerlifetime— External cancellation token that can remotely disable this provider (without impacting the original database instance)
Returns: Provider instance that will always return the db instance.
Disposing the original database, or cancelling the provided cancellation token will also trigger the cancellation of all the downstream scopes created from this provider.
CreateRootScope
static IFdbDatabaseScopeProvider<TState> CreateRootScope<TState>(IFdbDatabase db, Func<IFdbDatabase, CancellationToken, Task<(IFdbDatabase, TState)>> init, CancellationToken lifetime = null)
Create a scope that will execute some initialization logic before the first transaction is allowed to run
db— Parent providerinit— Handler that must run successfully once before allowing transactions on this scopelifetime— External cancellation token that can remotely disable this provider (without impacting the original database instance)
Returns: Provider instance that will always return the db instance.
Disposing the original database, or cancelling the provided cancellation token will also trigger the cancellation of all the downstream scopes created from this provider.
static IFdbDatabaseScopeProvider CreateRootScope(IFdbDatabase db, Func<IFdbDatabase, CancellationToken, Task> init, CancellationToken lifetime = null)
Create a scope that will execute some initialization logic before the first transaction is allowed to run
db— Parent databaseinit— Handler that must run successfully once before allowing transactions on this scopelifetime— Optional cancellation token that can be used to externally abort the new scope
CreateScope
static IFdbDatabaseScopeProvider CreateScope(IFdbDatabaseScopeProvider provider, Func<IFdbDatabase, CancellationToken, Task> init, CancellationToken lifetime = null)
Create a scope that will execute some initialization logic before the first transaction is allowed to run
provider— Parent providerinit— Handler that must run successfully once before allowing transactions on this scopelifetime— Optional cancellation token that can be used to externally abort the new scope
EnsureIsReady
static ValueTask EnsureIsReady(IFdbDatabaseScopeProvider provider, CancellationToken ct)
Wait for the scope to become ready.
QueryAsync
static Task<List<TResult>> QueryAsync<TResult>(IFdbDatabaseScopeProvider provider, Func<IFdbReadOnlyTransaction, IAsyncQuery<TResult>> handler, CancellationToken ct)
Runs a transactional lambda function inside a read-only transaction, which can be executed more than once if any retryable error occurs.
provider— Provider of the databasehandler— Asynchronous handler that will be retried until it succeeds, or a non-recoverable error occurs.ct— Token used to cancel the operation
Since the handler can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda! You must wait for the Task to complete successfully before updating the global state of the application.
static Task<List<TResult>> QueryAsync<TResult>(IFdbDatabaseScopeProvider provider, Func<IFdbReadOnlyTransaction, IAsyncEnumerable<TResult>> handler, CancellationToken ct)
Runs a transactional lambda function inside a read-only transaction, which can be executed more than once if any retryable error occurs.
provider— Provider of the databasehandler— Asynchronous handler that will be retried until it succeeds, or a non-recoverable error occurs.ct— Token used to cancel the operation
Since the handler can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda! You must wait for the Task to complete successfully before updating the global state of the application.
static Task<List<TResult>> QueryAsync<TResult>(IFdbDatabaseScopeProvider provider, Func<IFdbReadOnlyTransaction, Task<IAsyncQuery<TResult>>> handler, CancellationToken ct)
Runs a transactional lambda function inside a read-only transaction, which can be executed more than once if any retryable error occurs.
provider— Provider of the databasehandler— Asynchronous handler that will be retried until it succeeds, or a non-recoverable error occurs.ct— Token used to cancel the operation
Since the handler can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda! You must wait for the Task to complete successfully before updating the global state of the application.
static Task<List<TResult>> QueryAsync<TResult>(IFdbDatabaseScopeProvider provider, Func<IFdbReadOnlyTransaction, Task<IAsyncLinqQuery<TResult>>> handler, CancellationToken ct)
Runs a transactional lambda function inside a read-only transaction, which can be executed more than once if any retryable error occurs.
provider— Provider of the databasehandler— Asynchronous handler that will be retried until it succeeds, or a non-recoverable error occurs.ct— Token used to cancel the operation
Since the handler can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda! You must wait for the Task to complete successfully before updating the global state of the application.
static Task<List<TResult>> QueryAsync<TResult>(IFdbDatabaseScopeProvider provider, Func<IFdbReadOnlyTransaction, Task<IAsyncEnumerable<TResult>>> handler, CancellationToken ct)
Runs a transactional lambda function inside a read-only transaction, which can be executed more than once if any retryable error occurs.
provider— Provider of the databasehandler— Asynchronous handler that will be retried until it succeeds, or a non-recoverable error occurs.ct— Token used to cancel the operation
Since the handler can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda! You must wait for the Task to complete successfully before updating the global state of the application.
ReadAsync
static Task<TResult> ReadAsync<TResult>(IFdbDatabaseScopeProvider provider, Func<IFdbReadOnlyTransaction, Task<TResult>> handler, CancellationToken ct)
Runs a transactional lambda function inside a read-only transaction, which can be executed more than once if any retryable error occurs.
provider— Provider of the databasehandler— Asynchronous handler that will be retried until it succeeds, or a non-recoverable error occurs.ct— Token used to cancel the operation
Since the handler can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda! You must wait for the Task to complete successfully before updating the global state of the application.
static Task<TResult> ReadAsync<TState, TResult>(IFdbDatabaseScopeProvider<TState> provider, Func<IFdbReadOnlyTransaction, TState, Task<TResult>> handler, CancellationToken ct)
Runs a transactional lambda function inside a read-only transaction, which can be executed more than once if any retryable error occurs.
provider— Provider of the databasehandler— Asynchronous handler that will be retried until it succeeds, or a non-recoverable error occurs.ct— Token used to cancel the operation
Since the handler can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda! You must wait for the Task to complete successfully before updating the global state of the application.
ReadWriteAsync
static Task<TResult> ReadWriteAsync<TResult>(IFdbDatabaseScopeProvider provider, Func<IFdbTransaction, Task<TResult>> handler, CancellationToken ct)
Run an idempotent transactional block that returns a value, inside a read-write transaction, which can be executed more than once if any retry-able error occurs.
provider— Provider of the databasehandler— Idempotent asynchronous lambda function that will be retried until the transaction commits, or a non-recoverable error occurs. The returned value of the last call will be the result of the operation.ct— Token used to cancel the operation
Returns: Result of the lambda function if the transaction committed successfully.
You do not need to commit the transaction inside the handler, it will be done automatically. Since the can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda! You must wait for the Task to complete successfully before updating the global state of the application.
static Task<TResult> ReadWriteAsync<TState, TResult>(IFdbDatabaseScopeProvider<TState> provider, Func<IFdbTransaction, TState, Task<TResult>> handler, CancellationToken ct)
Run an idempotent transactional block that returns a value, inside a read-write transaction, which can be executed more than once if any retry-able error occurs.
provider— Provider of the databasehandler— Idempotent asynchronous lambda function that will be retried until the transaction commits, or a non-recoverable error occurs. The returned value of the last call will be the result of the operation.ct— Token used to cancel the operation
Returns: Result of the lambda function if the transaction committed successfully.
You do not need to commit the transaction inside the handler, it will be done automatically. Since the can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda! You must wait for the Task to complete successfully before updating the global state of the application.
WriteAsync
static Task WriteAsync(IFdbDatabaseScopeProvider provider, Func<IFdbTransaction, Task> handler, CancellationToken ct)
Run an idempotent transactional block that returns a value, inside a read-write transaction, which can be executed more than once if any retry-able error occurs.
provider— Provider of the databasehandler— Idempotent asynchronous lambda function that will be retried until the transaction commits, or a non-recoverable error occurs. The returned value of the last call will be the result of the operation.ct— Token used to cancel the operation
Returns: Result of the lambda function if the transaction committed successfully.
You do not need to commit the transaction inside the handler, it will be done automatically. Since the can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda! You must wait for the Task to complete successfully before updating the global state of the application.
static Task WriteAsync<TState>(IFdbDatabaseScopeProvider<TState> provider, Func<IFdbTransaction, TState, Task> handler, CancellationToken ct)
Run an idempotent transactional block that returns a value, inside a read-write transaction, which can be executed more than once if any retry-able error occurs.
provider— Provider of the databasehandler— Idempotent asynchronous lambda function that will be retried until the transaction commits, or a non-recoverable error occurs. The returned value of the last call will be the result of the operation.ct— Token used to cancel the operation
Returns: Result of the lambda function if the transaction committed successfully.
You do not need to commit the transaction inside the handler, it will be done automatically. Since the can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda! You must wait for the Task to complete successfully before updating the global state of the application.
static Task WriteAsync(IFdbDatabaseScopeProvider provider, Action<IFdbTransaction> handler, CancellationToken ct)
Run an idempotent transaction block inside a write-only transaction, which can be executed more than once if any retry-able error occurs.
provider— Provider of the databasehandler— Idempotent handler that should only call write methods on the transaction, and may be retried until the transaction commits, or a non-recoverable error occurs.ct— Token used to cancel the operation
You do not need to commit the transaction inside the handler, it will be done automatically. Since the can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda! You must wait for the Task to complete successfully before updating the global state of the application.
static Task WriteAsync<TState>(IFdbDatabaseScopeProvider<TState> provider, Action<IFdbTransaction, TState> handler, CancellationToken ct)
Run an idempotent transaction block inside a write-only transaction, which can be executed more than once if any retry-able error occurs.
provider— Provider of the databasehandler— Idempotent handler that should only call write methods on the transaction, and may be retried until the transaction commits, or a non-recoverable error occurs.ct— Token used to cancel the operation
You do not need to commit the transaction inside the handler, it will be done automatically. Since the can run more than once, and that there is no guarantee that the transaction commits once it returns, you MAY NOT mutate any global state (counters, cache, global dictionary) inside this lambda! You must wait for the Task to complete successfully before updating the global state of the application.