Skip to content

Enumerated types

Columns based on enumerated types are supported by monolayer-pg.

First, you declare an enum type with the enumType.

ts
import { enumType } from "@monolayer/pg/schema";

const role = enumType("role", ["admin", "user"]);

Then, you define columns based on this type with enumerated:

ts
import { enumerated, table } from "@monolayer/pg/schema";

const users = table({
  columns: {
    role: enumerated(role), 
  },
});

Lastly, you to add the type to the schema definition:

ts
const dbSchema = schema({
  types: [role],  
  tables: {
    users,
  },
});