Function: uuidV7()
uuidV7(args
: { lix
: Pick
<Lix
, "sqlite"
| "db"
| "hooks"
>; }): string
Returns a UUID v7 that is deterministic in deterministic mode.
In normal mode, returns a standard time-based UUID v7.
In deterministic mode, returns UUIDs with a fixed timestamp prefix and sequential counter suffix.
UUID v7 provides better database performance than nanoId due to time-based sorting,
but produces longer IDs that are less suitable for URLs.
- Normal mode: Standard UUID v7 with current timestamp
- Deterministic mode: Fixed prefix "01920000-0000-7000-8800-" + 12-digit hex counter
- Counter state shared with nextDeterministicSequenceNumber
- Choose UUID v7 for time-sortable database keys, nanoId for URL-friendly short IDs
Examples
const lix = await openLix();
uuidV7({ lix }); // "01920000-5432-7654-8abc-def012345678"
const lix = await openLix({
keyValues: [{ key: "lix_deterministic_mode", value: { enabled: true }, lixcol_version_id: "global" }]
});
uuidV7({ lix }); // "01920000-0000-7000-8000-000000000000"
uuidV7({ lix }); // "01920000-0000-7000-8000-000000000001"
uuidV7({ lix }); // "01920000-0000-7000-8000-000000000002"
await lix.db
.insertInto("change")
.values({
id: uuidV7({ lix }),
content: "Updated user profile"
})
.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
string
UUID v7 string