序列

要使用此功能,您需要 `[email protected]` 或更高版本以及 `[email protected]` 或更高版本。

PostgreSQL
SQLite
MySQL
SingleStore

PostgreSQL 中的序列是特殊的单行表,用于生成唯一标识符,通常用于自动递增的主键值。它们提供了一种线程安全的方式,可在多个会话中生成唯一的序列值。


主要特点


限制


实际应用


使用示例

import { pgSchema, pgSequence } from "drizzle-orm/pg-core";

// No params specified
export const customSequence = pgSequence("name");

// Sequence with params
export const customSequence = pgSequence("name", {
      startWith: 100,
      maxValue: 10000,
      minValue: 100,
      cycle: true,
      cache: 10,
      increment: 2
});

// Sequence in custom schema
export const customSchema = pgSchema('custom_schema');
export const customSequence = customSchema.sequence("name");