feat(ddl): CREATE SEQUENCE / DROP SEQUENCE + nextval/currval/setval helpers - #163
Merged
Merged
Conversation
…elpers
PG and MSSQL get first-class sequence DDL — a free-standing monotonic
integer source useful for advisory IDs, batch numbers, or counters that
need to outlive a particular table. PG also gets the runtime
`nextval('seq')` / `currval('seq')` / `setval('seq', n[, is_called])`
function-shape helpers; MSSQL's `NEXT VALUE FOR <seq>` grammar isn't a
function call and needs its own AST node (future work).
MySQL and SQLite refuse both surfaces via the new `SEQUENCES` /
`SEQUENCE_FNS` feature flags rather than emitting a statement the
engine will reject. The runtime gate fires inside `BasePrinter.printFunctionCall`
so the refusal lands at print time, pointing at the call site.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
productdevbook
force-pushed
the
worktree-agent-a3e4e8ca24aaadd25
branch
from
May 19, 2026 10:52
a7baf17 to
f25825e
Compare
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CREATE SEQUENCE/DROP SEQUENCEDDL on PG and MSSQL — a free-standing monotonic integer source independent of any particular table's lifecycle (auto-increment/IDENTITY columns are table-scoped; sequences are not). Useful for advisory IDs, batch numbers, cross-table counters.nextval('seq')/currval('seq')/setval('seq', n[, is_called])runtime helpers wired intoeb.tsand exposed as flatsumakexports.SEQUENCES/SEQUENCE_FNSfeature flags; the runtime gate fires insideBasePrinter.printFunctionCallso the refusal lands at print time with a clear error rather than driver-level parse failure.Surface (new)
db.schema.createSequence(name [, schema])→CreateSequenceBuilderwith.ifNotExists() .dataType(...) .increment(...) .minValue(...) .noMinValue() .maxValue(...) .noMaxValue() .start(...) .cache(...) .cycle() .noCycle() .ownedBy(table, column) .ownedByNone().db.schema.dropSequence(name [, schema])→DropSequenceBuilderwith.ifExists() .cascade().nextval(seqName),currval(seqName),setval(seqName, value [, isCalled]). Sequence names are validated against a SQL-identifier regex; numericvaluemust be a finite integer.Dialect divergence (handled at print time)
CREATE SEQUENCEIF NOT EXISTSOWNED BY …DROP SEQUENCE … CASCADEnextval/currval/setvalNEXT VALUE FOR)Test plan
pnpm fmt && pnpm lint && pnpm typecheck && pnpm vitest runall green (2286 passed, 58 skipped — +38 from new file).test/ddl/sequences.test.tswith 39 tests covering builder DSL, dialect emit shapes, refusal paths, and a PGlite roundtrip (create → nextval × 2 → currval → setval → nextval → drop).gh pr checks <N> --watchgreen.Tradeoffs
NEXT VALUE FOR <seq>is intentionally not supported in this cut — it's a sequence-value expression (not a function call), so cleanly bridging it needs a dedicated AST node and printer pass. Callers who need MSSQL sequence access today can fall back tounsafeRawExpr("NEXT VALUE FOR " + quotedName)when the name is trusted.nextval('order_no_seq')), not bound — PG's plan cache treats them that way, and binding would force per-call replan. The builder rejects names that aren't bare SQL identifiers to keep injection out of the literal slot.🤖 Generated with Claude Code