Function: timestamp()

timestamp(args: { lix: Pick<Lix, "sqlite" | "db" | "hooks">; }): string

Returns the current timestamp as an ISO 8601 string.

In deterministic mode, returns logical timestamps starting from Unix epoch (1970-01-01T00:00:00.000Z), incrementing by 1ms per call. In normal mode, returns the current system time.

  • In deterministic mode: Advances by exactly 1ms per call
  • Monotonically increasing (never goes backwards)
  • State persisted across reopens via lix_deterministic_sequence_number
  • Common uses: createdAt fields, TTL calculations, time-ordered queries

Examples

const lix = await openLix();
timestamp({ lix }); // "2024-03-15T10:30:45.123Z"
const lix = await openLix({
  keyValues: [{ key: "lix_deterministic_mode", value: { enabled: true } }]
});
timestamp({ lix }); // "1970-01-01T00:00:00.000Z"
timestamp({ lix }); // "1970-01-01T00:00:00.001Z" (+1ms)
timestamp({ lix }); // "1970-01-01T00:00:00.002Z" (+1ms)
await lix.db
  .insertInto("log")
  .values({
    id: "log1",
    created_at: timestamp({ lix }),
    message: "User logged in"
  })
  .execute();

Parameters

ParameterTypeDescription
args{ lix: Pick<Lix, "sqlite" | "db" | "hooks">; }-
args.lixPick<Lix, "sqlite" | "db" | "hooks">The Lix instance with sqlite and db connections

Returns

string

ISO 8601 timestamp string