generate
migrate
push
pull
check
up
studio
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"
select * from "schema"."users"
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' );
import { int, text, mysqlTable, mysqlSchema } from "drizzle-orm/mysql-core"; export const mySchema = mysqlSchema("my_schema") export const mySchemaUsers = mySchema.table("users", { id: int("id").primaryKey().autoincrement(), name: text("name"), });
CREATE SCHEMA "my_schema"; CREATE TABLE "my_schema"."users" ( "id" serial PRIMARY KEY, "name" text );
SQLite does not have support for schemas 😕