nanoId(
args: {length?:number;lix:Pick<Lix,"call"> &Record<string,unknown>; }):Promise<string>
Generate a nano ID.
Deterministic in deterministic mode; otherwise returns a random 21-character nano ID using the nanoid algorithm.
Use nano IDs when IDs will appear in URLs – their shorter length makes links easier to share. For better database performance with time-ordered queries, consider uuidV7 instead.
- or _).const lix = await openLix();
const id = await nanoId({ lix }) // "V1StGXR8_Z5jdHi6B-myT"const lix = await openLix({
keyValues: [{ key: "lix_deterministic_mode", value: { enabled: true }, lixcol_version_id: "global" }]
});
await nanoId({ lix }) // "test_0000000000"
await nanoId({ lix }) // "test_0000000001"
await nanoId({ lix }) // "test_0000000002"await lix.db
.insertInto("label")
.values({ id: await nanoId({ lix }), name: "bug", color: "#ff0000" })
.execute();| Parameter | Type | Description |
|---|---|---|
args | { length?: number; lix: Pick<Lix, "call"> & Record<string, unknown>; } | - |
args.length? | number | Optional length for non-deterministic mode (default: 21) |
args.lix | Pick<Lix, "call"> & Record<string, unknown> | Lix instance used to call into the engine. |
Promise<string>