Repository navigation
feat(dialect): add session transaction control - #409
Open
alexskinner wants to merge 1 commit into
Open
alexskinner wants to merge 1 commit into
alexskinner wants to merge 1 commit into
Conversation
cursor
Bot
force-pushed
the
upstream/dialect-transactions
branch
3 times, most recently
from
November 21, 2026 19:08
061b159 to
8d34bae
Compare
KKould
force-pushed
the
upstream/dialect-transactions
branch
2 times, most recently
from
November 21, 2026 20:27
3d5bf40 to
2f4e0b7
Compare
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (75.52%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #409 +/- ##
==========================================
- Coverage 92.98% 92.89% -0.09%
==========================================
Files 274 276 +2
Lines 39013 39479 +466
==========================================
+ Hits 36275 36674 +399
- Misses 2738 2805 +67
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
cursor
Bot
force-pushed
the
upstream/dialect-transactions
branch
from
November 22, 2026 11:02
2f4e0b7 to
c0b35f9
Compare
Contributor
Author
|
Rebased onto current main (after #407). Still a single commit, no conflicts. |
Add StartTransaction, Commit, Rollback and SetAutocommit statements to the KiteSQL AST. The generic parser lowers BEGIN or START TRANSACTION, COMMIT and ROLLBACK, rejecting transaction modes, savepoints and AND CHAIN, and lowers SET autocommit = 0 | 1 (or ON/OFF, TRUE/FALSE) only after SqlParser::with_set_autocommit(); otherwise SET autocommit is rejected like any other SET. The SQLite parser lowers BEGIN [DEFERRED], COMMIT/END and ROLLBACK. Add Database::session(), which returns a Session that runs these statements. Between BEGIN and COMMIT or ROLLBACK, statements run in one transaction, as with Transaction::run; outside one, each statement commits on its own, as with Database::run. COMMIT and ROLLBACK without an open transaction do nothing, and dropping the session rolls back an open transaction. With autocommit off, a statement outside a transaction opens one that stays open until COMMIT or ROLLBACK, and turning autocommit back on commits it. DDL and ANALYZE still go through Database::ddl and Database::analyze, and the other entry points reject transaction control statements. Add SqlDialect::begin_commits_active_transaction(), defaulting to false: when true, BEGIN inside an open transaction commits it and opens a new one; by default such a BEGIN is rejected and the open transaction is left as it was. DynDialect forwards it to its current dialect. Database::run and Transaction::run now delegate to run_statements, which the session reuses for statements it has already parsed. Their behaviour is unchanged. Unit tests in src/db/session.rs cover the default and a test-only dialect that parses SET autocommit and turns the hook on. Co-authored-by: Alex Skinner <alexskinner@users.noreply.github.com>
cursor
Bot
force-pushed
the
upstream/dialect-transactions
branch
from
November 22, 2026 17:37
c0b35f9 to
8a8bac6
Compare
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.
Part of #403.
Reworked on top of #410: the transaction control statements are now part of the KiteSQL AST, and the dialect's parser decides which of them it accepts.
What
Statement::StartTransaction,Commit,RollbackandSetAutocommit(bool).BEGIN/START TRANSACTION,COMMITandROLLBACK, and rejects transaction modes, savepoints andAND CHAIN.SET autocommit = 0 | 1(andON/OFF,TRUE/FALSE) is lowered only afterSqlParser::with_set_autocommit(). Otherwise it is rejected like any otherSET, as today.BEGIN [DEFERRED],COMMIT/ENDandROLLBACK, soSessionworks withSqliteDialecttoo. Named transactions,IMMEDIATE/EXCLUSIVEand savepoints stay rejected.Database::session(), which returns aSessionthat runs those statements:BEGINandCOMMIT/ROLLBACK, statements run in one transaction, as withTransaction::run. Outside a transaction, each statement commits on its own, as withDatabase::run.COMMITandROLLBACKwithout an open transaction do nothing. Dropping the session rolls back an open transaction.COMMITorROLLBACK, and turning autocommit back on commits it.ANALYZEstill go throughDatabase::ddlandDatabase::analyze, with the same errors as today.Database::run,Transaction::runand the other entry points reject transaction control statements and point toDatabase::session.Session::runtakes one statement at a time.autocommit()andin_transaction()report the session's state.SqlDialecthook,begin_commits_active_transaction(), defaulting tofalse. Whentrue,BEGINinside an open transaction commits it and opens a new one. By default such aBEGINis rejected and the open transaction is left as it was.DynDialectforwards it.Database::runandTransaction::runnow delegate to a crate-privaterun_statements, which the session reuses for the statement it has already parsed. Neither public method changes behaviour.Session, the parser option and the hook, a line in the MVCC section and a line in the dialect section ofdocs/features.md.Why
Drivers and connection pools send transaction control as SQL. Today that only works through the CLI shell, which special-cases those strings. A
Sessiongives embedders the same thing through the library. Dialects also differ on the details: MySQL-compatible clients expect a nestedBEGINto commit implicitly and useSET autocommit = 0, while the standard behaviour is to reject both. With #410 a dialect crate opts intoSET autocommitin its ownparseand picks the nestedBEGINbehaviour through the hook, without branches in core. See #403.Testing
src/db/session.rs, on the default test storage for both the sync and async builds: with the generic dialect a nestedBEGINandSET autocommitare rejected and the open transaction still commits; with a test-only dialect whoseparsecallsSqlParser::with_set_autocommit(), a nestedBEGINcommits, and autocommit off opens a transaction that turning it back on commits.test_prepare_and_command_type_classificationcase forstart transactionnow checks thatcommand_typerejects it with a pointer toDatabase::session, since the parser accepts it.make test(657 passed, 2 ignored),make test-async(602 passed),make test-sltandmake test-slt-async(198 files each),make fmtand all fourmake clippyinvocations pass.Notes for review
src/dialect/mod.rs,src/parser/genericanddocs/features.mdas that PR, so whichever lands second needs a trivial rebase.SET autocommitgate lives in the parser rather than in aSqlDialecthook, following feat: KiteSQL AST and SQLite dialect #410's "the dialect rejects syntax it does not support" rule. Only the nestedBEGINbehaviour, which is semantics, stays a hook.Sessionis additive. Nothing that exists today goes through it, and with the default dialect the only new behaviour is the session itself.Transaction::rundoes today.ROLLBACKdiscards it. Statement-level rollback inside a transaction would need savepoint support in the storages, so I left it out of scope.Databaseon the same thread while a session holds a write transaction waits for that transaction. The rustdoc says to send every statement through the session while it has one open.src/bin/shell.rsover toSession, to keep this PR to one concern. I'm happy to do that in a follow-up if you'd like.