Ruff fails CI with C901: `batch` scored 11 against the limit of 10. The
method was doing two jobs, and the step-building half re-tested
`begin_sql is not None` four separate times while threading an `offset`
through every index computation.
Move step building into `_build_batch_steps`, where the transactional and
non-transactional shapes each build their own list with concrete indices
instead of interleaving. No behavior change: the emitted steps, the index
of the first statement step, and the COMMIT index are identical to what
the old code produced.
Tests: `uvx ruff@0.5.4 check` passes; `pytest tests/test_serverless.py`
passes (the batch tests needing a live server stay skipped). Also diffed
the new helper against the pre-refactor step building for transactional
and non-transactional batches with positional, named, and no parameters —
identical output in every case.
Parameterized batches could produce different effects across embedded and
serverless drivers when a later bind value was invalid. Embedded Rust also
allowed cloned connections to interleave work with a batch, and managed
batches allowed transaction-control statements to escape their wrapper.
Rollback failures were hidden, while serverless Rust could retain a stale
last-insert rowid when COMMIT failed after a successful insert.
Validate every batch input before execution, reject transaction-control SQL
before opening a managed transaction, and hold an operation-wide gate for
embedded Rust batches. Preserve both the primary and rollback errors, and
carry successful statement rowids through serverless batch decoding even
when a synthetic transaction step fails. Reject malformed serverless batch
responses instead of treating incomplete transaction steps as success.
State the parity requirement in the serverless differential conformance
spec — each serverless driver exposes the same public API as its
language's embedded driver, and non-JavaScript serverless drivers track
the JavaScript driver's capabilities — and reference it from the
AGENTS.md core principles.
Add the param_batch operation to the shared vocabulary (spec/ops.json,
documented in operations.md) and implement it in the JavaScript,
Python, and Rust harnesses: 1-4 statements through the batch() API —
parameterized INSERTs drawing from the adversarial value pool, SELECTs,
and statements from error_sqls — optionally atomic via a mode of
deferred or immediate. The embedded and serverless drivers must agree
on every statement's result; on failure they must agree on the failing
statement's index and on the per-statement results carried by the
error, entry by entry. An agreed batch failure leaves well-defined
state, so the harnesses keep comparing later operations — that is what
catches an atomic batch that reports the right index but fails to roll
back. The server-side execution statistics are excluded from the
comparison: the serverless driver reports them and the embedded driver
does not, by design.
The embedded drivers execute a batch as a sequential loop that stops at
the first error, so the comparison is the oracle for the serverless
batch: one pipeline request must behave exactly like sequential
execution that stops at the first failure.
The Rust generator fails the suite deterministically, with an
actionable message, when ops.json contains an operation it does not
implement, instead of panicking mid-case on an unknown id.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add Connection.batch(statements, mode=None) to turso (bindings/python,
inherited by the sync driver's ConnectionSync and exposed on the aio
wrapper) and to turso_serverless, with the same signature and semantics
per the driver API parity requirement.
Statements are SQL strings or (sql, parameters) pairs and execute in
order, stopping at the first failure; the raised exception keeps its
DB-API class, prefixes the message with the zero-based statement index,
and carries batch_index and batch_results attributes — the latter with
one entry per statement, so callers can tell exactly which statements
took effect before the failure. A client-side value encoding failure is
reported the same way. With mode set (deferred, immediate, exclusive,
concurrent) the statements are wrapped in BEGIN/COMMIT with a ROLLBACK
on failure for all-or-nothing execution. batch() never opens a legacy
implicit transaction; statements join an already-open transaction, in
which case mode is ignored.
Each statement's BatchResult carries rows, description, rowcount, and
lastrowid, plus the server-side execution statistics rows_read,
rows_written, and query_duration_ms reported by the serverless protocol
(the embedded engine does not report them per statement). The
serverless driver sends the whole batch, including the transaction
wrapper, as a single pipeline request, so a multi-statement
parameterized batch is one HTTP round trip.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Drop the wire-level every-request detail and the PROTOCOL.md reference
from user-facing driver docs, and use named return parameters in the Go
parseDSN to disambiguate the three returned strings.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Only the JavaScript serverless driver supported a remote encryption key,
sent as the x-turso-encryption-key header. Add the same support to the
Go, Python, and Rust drivers:
- Go: remote_encryption_key DSN parameter and
Connector.WithRemoteEncryptionKey
- Python: connect(remote_encryption_key=...)
- Rust: Builder::with_remote_encryption_key
Document the header in PROTOCOL.md section 3.1 and make it an enforced
property: the shared differential spec gains a tests.encryption_header
entry, and every harness now runs a property test against a local stub
HTTP server asserting that a driver configured with a key attaches the
header to every request on both the pipeline and cursor endpoints, and
that a driver without a key never sends it. These tests need no Turso
Cloud database and never skip.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The driver has a full DB-API 2.0 surface and conformance test
coverage, so the Development Status :: 3 - Alpha classifier
undersells its maturity on PyPI. Bump it to 4 - Beta.
Implement the client side of the SQL over HTTP protocol
(serverless/PROTOCOL.md) so Python applications can talk to Turso Cloud
from serverless and edge environments, where the only networking
primitive is an HTTP request. The driver is pure Python on top of
urllib, implements DB-API 2.0, and mirrors the embedded turso driver,
so the same code runs against a local database or Turso Cloud.
The session layer follows the JavaScript and Rust serverless drivers:
the baton is tracked on every request, transaction state comes from the
server's authoritative get_autocommit answer piggybacked on every
pipeline (and an is_autocommit-gated probe step on cursor batches), and
statements run over the cursor endpoint. Pipeline responses are
validated to carry one result per request. A failed request is never
transparently retried: the stream is reset and the error surfaces, so
the application decides whether re-running a statement is safe.
Server-returned base URLs go through the same normalization as
user-supplied ones, including trailing-slash stripping.
The conformance suite runs against a live database configured with
TURSO_DATABASE_URL and TURSO_AUTH_TOKEN and skips when they are unset,
covering queries, parameter binding, value round-trips, transactions,
executescript, and DB-API error mapping.
Tests: pytest in serverless/python; protocol and URL handling unit
tests run standalone, the conformance suite needs the environment
variables set.