idPlugin
idPlugin(
map):KyselyPlugin
Defined in: src/adapters/kysely.ts:162
Kysely plugin that automatically transforms result columns using the provided codec map.
Unbranded map — callers own the key-to-column mapping. The map parameter is typed as
Record<string, IdColumnCodec<string>> with no schema-level brand parameter. There is no
compile-time guarantee that map keys correspond to actual columns in your Database interface;
a misspelled or stale key silently matches nothing, and the column is left un-transformed.
Callers are responsible for keeping the map in sync with their schema.
Keys must be bare column names (e.g. "id", "user_id"). Qualified keys containing a
dot (e.g. "users.id") are not supported — passing one throws a synchronous Error at
construction time, naming the offending key. Per-table disambiguation is not implemented.
transformResult calls readIdColumn(codec, rawValue) for each matched column, returning
a branded Id<Brand> on success and throwing IdsError("invalid_id") on parse failure.
transformQuery is a no-op identity pass-through.
Parameters
Section titled “Parameters”Record<string, IdColumnCodec<string>>
Returns
Section titled “Returns”KyselyPlugin
Example
Section titled “Example”import { idPlugin } from "@smonn/ids/kysely";import { createTimestampId } from "@smonn/ids";import { Kysely } from "kysely";
const usr = createTimestampId("usr");
const db = new Kysely<Database>({ // ... plugins: [idPlugin({ id: usr })],});
// result.id is automatically validated and branded as Id<"usr">const row = await db.selectFrom("users").selectAll().executeTakeFirstOrThrow();