Database Schemas
Each PostgreSQL database contains one or more named schemas which contain tables and other database objects.
Normally, every database in PostgreSQL contains a public
schema by default.
Define the public schema
You define the database public schema with the schema
function.
ts
export const dbSchema = schema({});
See the list of configuration properties in the DatabaseSchema Reference
Define a named schema
You define a named database schema by giving it a name.
ts
export const statsSchema = schema({
name: "stats",
});
TIP
monolayer-pg
will handle the creation of the schemas other than the default public
.
Connecting a schema to a database
In your databases.ts
file, specify the schema(s) you want to use in a defined database.
ts
import { defineDatabase } from "@monolayer/pg/schema";
import { dbSchema } from "./schema";
export const defaultDb = defineDatabase({
schemas: [dbSchema],
});