Commit Graph

41 Commits

Author SHA1 Message Date
PThorpe92
9fe63ac8f0 SDK/drivers: make parameterized batches safe and consistent
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.
2026-08-28 10:40:26 -07:00
Glauber Costa
e29fe1033d add a parameterized batch API to the embedded and serverless Python drivers
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>
2026-08-28 10:40:26 -07:00
Orthel Toralen
be8de4b1ec bindings/python: reject sqlite3.Row row_factory with explicit error 2026-07-27 21:33:39 -04:00
Pekka Enberg
8a625a8470 python: enable Tantivy FTS and add tests
The `fts` cargo feature (which pulls in tantivy) propagated from `core`
to `sdk-kit` but stopped there: `py-turso` depended on `turso_sdk_kit`
without enabling `fts`, so `CREATE INDEX ... USING fts` failed at runtime
even with the `index_method` experimental flag set.

Enable `turso_sdk_kit/fts` in the Python binding so FTS is compiled into
the wheel. Usage is SQL-only and gated at runtime via
`turso.connect(..., experimental_features="index_method")`.

Add three FTS tests to test_database.py (run unconditionally in CI on all
platforms) covering fts_match, fts_score ordering, and fts_highlight.
2026-06-09 10:06:34 +03:00
Akira Noda
bb58bf5322 feat: named parameter support in python binding 2026-04-22 15:00:00 +09:00
Avinash Sajjanshetty
4784e784a3 fix python encryption test 2026-01-28 11:27:39 +05:30
Avinash Sajjanshetty
5c59f1e1af Add a simple encryption test in python bindings 2026-01-20 16:55:52 +05:30
Nikita Sivukhin
28094f4b0b fix python bindings 2025-12-26 17:22:34 +04:00
Nikita Sivukhin
3913206abc fix python test 2025-12-23 15:55:57 +04:00
Nikita Sivukhin
51e162e8cf uv ruff 2025-12-23 15:34:43 +04:00
Nikita Sivukhin
e109b837b0 adjust python bindings 2025-12-23 15:34:43 +04:00
Pekka Enberg
df9c39cd1c core: Fix integrity_check pragma code generation
The translate_integrity_check function was missing a call to
add_pragma_result_column, causing num_columns() to return 0.
This made the Python bindings treat it as a non-row-returning
statement, finalizing it during execute() and leaving fetchone()
to return None instead of ("ok",).

Spotted by Antithesis.
2025-12-15 09:46:46 +02:00
Nikita Sivukhin
82fd3d0c2c adjust tests 2025-12-09 15:42:29 +04:00
Nikita Sivukhin
4c5dfbaefe format fixes 2025-12-09 15:42:29 +04:00
Nikita Sivukhin
9be21e259a wip 2025-12-09 15:42:29 +04:00
Nikita Sivukhin
769af9485e remove debug print 2025-11-28 03:31:46 +04:00
Nikita Sivukhin
4add1de3e7 uvx ruff check 2025-11-28 03:31:16 +04:00
Nikita Sivukhin
863c9727cc uv format 2025-11-28 03:22:16 +04:00
Nikita Sivukhin
338846eeda bit more tests and fix __init__ 2025-11-28 02:51:58 +04:00
Nikita Sivukhin
caefe25ad5 more tests from robots 2025-11-28 01:54:04 +04:00
Nikita Sivukhin
c84b51510b fix tests: bug in assertion + adjust driver usage in the tricky INSERT RETURNING test 2025-11-28 01:45:13 +04:00
Nikita Sivukhin
c95908bca5 uv format + remove unused imports 2025-11-28 01:42:11 +04:00
Nikita Sivukhin
5fb16eb9d1 generate tests with prompt 2025-11-28 01:39:25 +04:00
Nikita Sivukhin
dd913dec22 move connect at the top 2025-11-28 01:06:44 +04:00
Nikita Sivukhin
857f9147f6 enable indices in the python SDK 2025-08-13 16:10:27 +04:00
Pekka Enberg
5216e67d53 bindings/python: Start transaction implicitly in execute()
We need to start transaction implicitly in execute() for DML statements
to make sure first transaction is actually started.

Fixes #2002
2025-07-09 10:59:52 +03:00
Pekka Enberg
a5b539f1bf bindings/python: Rename package to pyturso 2025-06-27 11:27:08 +03:00
pedrocarlo
80ccca8827 ruff lint fix 2025-06-20 15:59:03 -03:00
Pere Diaz Bou
4514bd5681 use integer primary key on test_in_memory_fetchone_select_all_users 2025-06-17 19:33:23 +02:00
Diego Reis
160d48d34e ext/python: Workaround to file permission error
To get more info see:
https://github.com/tursodatabase/limbo/actions/runs/14039536389/job/39312362848
2025-03-24 16:39:24 -03:00
Diego Reis
6edf3dd3b1 ext/python: Makes linter happy 2025-03-24 12:40:59 -03:00
Diego Reis
4ca5b11bed ext/python: Add support for Context Manager 2025-03-24 12:20:13 -03:00
Diego Reis
2ee934577f ext/python: Close connection after each test 2025-03-21 12:02:27 -03:00
Diego Reis
3c2bb6c3a8 ext/python: Fix flaky tests by creating a new db for each test and removing it after the test 2025-03-21 11:33:24 -03:00
Diego Reis
f966f7ad0e ext/python: Makes Linter happy 2025-03-20 17:40:31 -03:00
Diego Reis
16b9325830 ext/python: Basic support for placeholding insert 2025-03-20 17:10:12 -03:00
JeanArhancet
2a0402ce7f fix: python lint 2024-12-30 10:21:11 +01:00
JeanArhancet
cb69d8b0dd feat(python): add in-memory mode 2024-12-30 10:21:11 +01:00
Lauri Virtanen
6bd1d28e26 Format Python bindings code using Ruff
- Use double quotes (Ruff/Black default)
- Configure some set of linters to use with Ruff
2024-09-01 16:10:59 +03:00
JeanArhancet
fc2962e04e ci: integrate pyo3
ci: add manylinux

fix: maturin build error

ci: add wheels upload

ci: use venv
2024-08-25 21:47:17 +02:00
JeanArhancet
7c362b129f feat: impl python binding
refactor: pep-0249

refactor: rust comment and requirements-dev.txt

fix: name conflict
2024-08-11 08:58:18 +02:00