Function: nextDeterministicSequenceNumber()
nextDeterministicSequenceNumber(args
: { lix
: Pick
<Lix
, "sqlite"
| "db"
| "hooks"
>; }): number
Returns the next monotonic sequence number, starting at 0.
Only available in deterministic mode. Provides a simple counter for cases where
you need sequential integers rather than timestamps or random values.
- Requires
lix_deterministic_mode = true
- Increments by exactly 1 per call (no gaps or duplicates)
- State persisted via
lix_deterministic_sequence_number
key value
- Clones continue from where the sequence left off
- Consider using timestamp, uuidV7, or nanoId for most ID generation needs
Examples
const lix = await openLix({
keyValues: [{ key: "lix_deterministic_mode", value: { enabled: true } }]
});
const n1 = nextDeterministicSequenceNumber({ lix }); // 0
const n2 = nextDeterministicSequenceNumber({ lix }); // 1
const n3 = nextDeterministicSequenceNumber({ lix }); // 2
const n = nextDeterministicSequenceNumber({ lix }); // e.g. 7
const id = `ENTITY_${n}`; // "ENTITY_7"
const cursor = nextDeterministicSequenceNumber({ lix });
await lix.db.insertInto("page_view")
.values({ cursor, page_id: "home" })
.execute();
Parameters
Parameter | Type | Description |
---|
args | { lix : Pick <Lix , "sqlite" | "db" | "hooks" >; } | - |
args.lix | Pick <Lix , "sqlite" | "db" | "hooks" > | The Lix instance with sqlite and db connections |
Returns
number
The next number in the sequence (starting from 0)
Throws
If lix_deterministic_mode
is not enabled