Skip to main content

Module keys

Module keys 

Source
Expand description

Key encoding for Kit indexes, guards, and primary keys.

§Format

Each encoded key is a colon-separated (:) string of typed components. A component is one of:

  • i:<value> – a signed integer value (mirrors a TypeScript bigint).
  • s:<text> – a string value. Colons and backslashes in <text> are escaped as \: and \\ respectively.
  • n:null – an explicit SQL NULL marker.

encode_pk joins components directly with : and is suitable for use as a primary-key literal inside other keys. encode_unique_key prefixes the components with uq:<version>:<constraint_name>: so the resulting string is globally unique per constraint. encode_row_guard_key prefixes an already-encoded primary key with rg:<table_name>:.

This matches the TypeScript kit (src/keys.ts) byte-for-byte so the three languages produce identical guard and unique-key entries. In particular the typed i:/s: prefixes guarantee that the integer 1 and the text "1" never collide.

Enums§

KeyComponent
A single typed key component.

Constants§

KIT_KEY_VERSION
Stable on-disk format version embedded in unique-key encodings.

Functions§

decode_pk
Decode an encoded primary key into its typed components.
encode_component
Encode a single typed component.
encode_pk
Encode a primary key value.
encode_row_guard_key
Encode a row-guard key for optimistic foreign-key checks.
encode_unique_key
Encode a unique-constraint key.