Become a Gold Sponsor

Table schemas

PostgreSQL
MySQL
SQLite
SingleStore

Drizzle ORM provides you an API for declaring SQL schemas for PostgreSQL and MySQL dialects.

If you declare an entity within a schema, query builder will prepend schema names in queries:
select * from "schema"."users"

PostgreSQL
MySQL
SQLite
SingleStore
import { serial, text, pgTable, pgSchema } from "drizzle-orm/pg-core";

export const mySchema = pgSchema("my_schema");

export const colors = mySchema.enum('colors', ['red', 'green', 'blue']);

export const mySchemaUsers = mySchema.table('users', {
  id: serial('id').primaryKey(),
  name: text('name'),
  color: colors('color').default('red'),
});

CREATE SCHEMA "my_schema";

CREATE TYPE "my_schema"."colors" AS ENUM ('red', 'green', 'blue');

CREATE TABLE "my_schema"."users" (
  "id" serial PRIMARY KEY,
  "name" text,
  "color" "my_schema"."colors" DEFAULT 'red'
);