시퀀스
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");