序列
PostgreSQL
SQLite
MySQL
SingleStore
MSSQL
CockroachDB
PostgreSQL 和 CockroachDB 中的序列是特殊的单行表,创建用于生成唯一标识符,通常用于自动递增主键值。它们提供了一种线程安全的方式,在多个会话中生成唯一的连续值。
import { pgSchema, pgSequence } from "drizzle-orm/pg-core";
// 未指定参数
export const customSequence = pgSequence("name");
// 带参数的序列
export const customSequence = pgSequence("name", {
startWith: 100,
maxValue: 10000,
minValue: 100,
cycle: true,
cache: 10,
increment: 2
});
// 自定义架构中的序列
export const customSchema = pgSchema('custom_schema');
export const customSequence = customSchema.sequence("name");