Become a Gold Sponsor

表结构

PostgreSQL
MySQL
SQLite

Drizzle ORM 为 PostgreSQL 和 MySQL 方言提供了一个用于声明 SQL 架构的 API。

如果在架构中声明了一个实体,查询构建器会在查询中添加架构名称:
select * from "schema"."users"

PostgreSQL
MySQL
SQLite
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'
);