Class SqliteKeyGenerator

Namespace: redb.SQLite.Data
Assembly: redb.SQLite.dll

SQLite implementation of key generator. Ids come from the native
AUTOINCREMENT table _global_identity; its high-water mark lives in
sqlite_sequence. A batch of N ids is reserved with one atomic statement:
UPDATE sqlite_sequence SET seq = seq + WHERE name='_global_identity'
RETURNING seq;
which returns the new top; the reserved ids are [top-N+1 .. top].
No explicit locking is needed — SQLite serializes writers and the
read-modify-write happens inside the single UPDATE (RETURNING: 3.35+).
The same sequence is also advanced by the C extension (nextId) and by
soft-delete (INSERT DEFAULT VALUES); all consumers only ever increase it,
so ids are globally unique. Caching is static in the base class.

public class SqliteKeyGenerator : RedbKeyGeneratorBase, IKeyGenerator

Inheritance

Object→RedbKeyGeneratorBase→SqliteKeyGenerator

Implements

Inherited Members

Methods

GenerateKeysAsync(int)

Reserve a contiguous batch of count ids by bumping the

protected override Task<List<long>> GenerateKeysAsync(int count)

TryGenerateKeysInAmbientTransactionAsync(int)

The single-writer bypass: the same atomic sequence bump, but on the scope's own

protected override Task<List<long>?> TryGenerateKeysInAmbientTransactionAsync(int count)

Constructors

SqliteKeyGenerator(string, string?)

Create SQLite key generator from connection string.