Function: uuid()
uuid():
PgUuid
Column that stores Universally Unique Identifiers (UUID).
Returns
Remarks
Kysely database schema type definition
ts
{
readonly __select__: string | null;
readonly __insert__: string | null | undefined;
readonly __update__: string | null;
};
Nullability and optionality will change according to the column's constraints, generated values, and default data values.
Zod Schema
Types:
ts
{
input?: string | null | undefined;
output?: string | null | undefined;
}
Nullability and optionality will change according to the column's constraints, generated values, and default data values.
Validations:
- Explicit
undefined
values are rejected. - Input value must be
string
, ornull
. - String values must be a valid UUID.
Example
ts
import { uuid, schema, sql, table } from "monolayer/pg";
import { zodSchema } from "monolayer/zod";
const dbSchema = schema({
tables: {
example: table({
columns: {
id: uuid().default(sql`gen_random_uuid()`),
},
}),
},
});
// Kysely database schema type
type DB = typeof dbSchema.infer;
// Zod Schema
const schema = zodSchema(database.tables.example);
See
PostgreSQL Docs: uuid