feat(ddl): TRUNCATE TABLE typed builder with full PG grammar - #168
Merged
Conversation
Adds a first-class TRUNCATE entry point — `truncate(table | tables)` and `db.schema.truncate(...)` — that exposes the full PostgreSQL grammar (`ONLY`, `RESTART IDENTITY` / `CONTINUE IDENTITY`, `CASCADE` / `RESTRICT`, comma-separated multi-table list) while degrading gracefully on MySQL / MSSQL (simple form only) and SQLite (refused with a pointer at `db.deleteFrom(t).allRows()`). The existing `db.schema.truncateTable(name)` factory + `TruncateTableBuilder` keeps the single-table API working unchanged; the new factory just expands the grammar surface. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
truncate(table | tables)factory +db.schema.truncate(...)that surfaces the full PostgreSQLTRUNCATEgrammar (ONLY,RESTART IDENTITY/CONTINUE IDENTITY,CASCADE/RESTRICT, comma-separated multi-table list).TRUNCATE TABLE <name>form (no multi-table, no modifiers — printer points atALTER TABLE … AUTO_INCREMENT/DBCC CHECKIDENTfor the identity-reset case), SQLite refuses outright with a pointer atdb.deleteFrom(t).allRows()as the workaround.db.schema.truncateTable(name)+TruncateTableBuilderworking unchanged so no caller breaks.TRUNCATE_TABLE(PG/MySQL/MSSQL) andTRUNCATE_PG_OPTIONS(PG only). Recipe section added todocs/recipes.md.Test plan
pnpm fmt && pnpm lint && pnpm typecheckall greenpnpm vitest run— 2507 tests pass (41 new intest/ddl/truncate.test.ts)ONLY/RESTART IDENTITY/CASCADE/ all-in-combination emissionDELETE FROMdb.schema.truncateTable(name)tests still pass🤖 Generated with Claude Code