monolayer-pg / schema / enumerated
Function: enumerated()
enumerated<
Value
>(enumerated
):PgEnum
<Value
>
Column that stores a static, ordered set of values.
Type Parameters
Type Parameter |
---|
Value extends string |
Parameters
Parameter | Type |
---|---|
enumerated | EnumType <Value > |
Returns
PgEnum
<Value
>
Remarks
Kysely database schema type definition
ts
const role = enumType("role", ["admin", "user"]);
const roleColumn = enumerated(role);
type RoleColumn = {
readonly __select__: "admin" | "user" | null;
readonly __insert__: "admin" | "user" | null | undefined;
readonly __update__: "admin" | "user" | null;
};
Nullability and optionality will change according to the column's constraints, generated values, and default data values.
Example
ts
import { enumerated, enumType, schema, table } from "@monolayer/pg/schema";
const role = enumType("role", ["admin", "user"]);
const dbSchema = schema({
types: [role],
tables: {
example: table({
columns: {
role: enumerated(role),
},
}),
},
});
// Kysely database schema type
type DB = typeof dbSchema.infer;
See
PostgreSQL Docs: enumerated types