mirror of
https://github.com/allankoechke/turso.git
synced 2026-12-01 17:43:08 +00:00
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>