BEGIN, COMMIT, and ROLLBACK, and also runs each standalone statement in an implicit transaction (autocommit mode).
Syntax
BEGIN
Starts a new explicit transaction. While a transaction is open, all subsequent statements are part of that transaction until aCOMMIT or ROLLBACK is issued.
Transaction types
| Type | Description |
|---|---|
DEFERRED | Default. No locks are acquired until the first read or write operation. A read operation acquires a shared lock; a write operation acquires a write lock. |
IMMEDIATE | Acquires a write lock immediately when BEGIN is executed. Other connections can still read but cannot write until the transaction completes. |
EXCLUSIVE | Same behavior as IMMEDIATE in Turso. Turso always uses WAL mode, where EXCLUSIVE and IMMEDIATE are equivalent. |
COMMIT / END
Finalizes the transaction and writes all changes to the database. Once committed, changes are durable and visible to other connections.COMMIT and END are interchangeable.
ROLLBACK
Aborts the current transaction and reverts all changes made sinceBEGIN. The database is left in the state it was in before the transaction started.
Implicit transactions (autocommit)
When no explicit transaction is active, Turso wraps each individual statement in an implicit transaction. Each statement is automatically committed after it executes successfully, or automatically rolled back if it fails.Transaction lifecycle
Turso does not support
SAVEPOINT or nested transactions. Each connection can have at most one active transaction at a time.BEGIN CONCURRENT
Turso extension:
BEGIN CONCURRENT is a Turso-specific extension not available in standard SQLite. It requires MVCC mode.BEGIN CONCURRENT statement starts an optimistic concurrent write transaction that allows multiple connections to write simultaneously.
Syntax
Requirements
BEGIN CONCURRENT requires MVCC mode. Enable it by setting the journal mode before opening any transactions:
How it works
A concurrent transaction operates on a snapshot of the database taken at the time ofBEGIN CONCURRENT. Each connection reads from its own snapshot and writes independently.
When COMMIT is issued, Turso checks whether any other transaction has modified the same rows since the snapshot was taken:
- If there is no conflict, the transaction commits successfully.
- If a write-write conflict is detected, the
COMMITfails and the transaction must be rolled back and retried.
Example
COMMIT fails: