10 Commits

Author SHA1 Message Date
Pure Tech
1123951041 serverless/js: fix broken README links and add repository field 2026-09-01 12:08:53 -04:00
Glauber Costa
a368eab3af js: return full per-statement details from batch() in every driver
The protocol reports complete per-statement information for a batch —
results, last insert rowid, error codes, and the execution statistics
rows_read, rows_written, and query_duration_ms — but batch() dropped
most of it. Extend the batch API compatibly, in the serverless driver
and in the embedded driver (@tursodatabase/database, whose
DatabasePromise is shared by the wasm and sync drivers), per the driver
API parity requirement:

- Each ResultSet also carries lastInsertRowid, plus rowsRead,
  rowsWritten, and queryDurationMs on the serverless driver (the
  embedded engine does not report those per statement). The
  lastInsertRowid key is present only on entries whose statement
  inserted, so `"lastInsertRowid" in resultSet` detects an insert.
- The serverless batch() uses a pipeline batch request instead of the
  cursor endpoint, because the cursor stream does not carry the
  statistics, and gates each statement on its predecessor succeeding,
  so execution stops at the first failure instead of running the
  remaining statements against a failed batch — the embedded driver's
  sequential semantics.
- The thrown error carries batchIndex (the zero-based index of the
  failing statement) and batchResults (one entry per statement: the
  completed statement's ResultSet, or null for the failing and skipped
  ones; empty when a bind value fails to encode client-side before
  anything is sent), so callers can tell exactly which statements took
  effect.
- The libsql-compat batch() returns the full libSQL ResultSet shape —
  lastInsertRowid and toJSON() included, matching @libsql/client, whose
  batch() returns the same ResultSet as execute() — and both of its
  batch entry points preserve batchIndex and batchResults on the
  LibsqlError they throw.

The JavaScript conformance contract covers the per-statement detail
fields. Also update the serverless integration tests that still
asserted positional access on expanded rows, removed in f52724d45.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-28 10:40:25 -07:00
Pekka Enberg
3e246552e9 serverless: remove Connection.execute() from the main API
The serverless driver's main entry point is meant to mirror the native
@tursodatabase/database surface, which has no execute() — it exposes
prepare/run/get/all/iterate/exec/batch/pragma/transaction. Connection.execute()
was a libsql-client-ism on that surface, and it returned the raw protocol
result shape rather than the {changes, lastInsertRowid} / row-array contracts
the sibling methods use.

The libsql compatibility layer keeps its own execute(), which talks to
Session.execute() directly and never went through Connection.execute(), so the
compat surface is unaffected.

Tests: rewrote the serverless integration tests and the serverless-only
conformance tests against exec/run/get/all; tsc and the package build pass.
Both suites need a live TURSO_DATABASE_URL and were not run.
2026-07-20 18:29:15 +03:00
Nikita Sivukhin
8069982e0d fix example 2026-07-17 14:45:58 +02:00
Nikita Sivukhin
74311642b0 allow to pass arbitrary request headers in the queries through queryOptions 2026-07-17 13:37:15 +02:00
Nikita Sivukhin
90ae357645 add validation for requestHeaders parameter 2026-06-11 19:25:27 +02:00
Nikita Sivukhin
2006463cff add requestHeaders option so that user can set arbitrary headers for serverless driver 2026-06-08 08:58:08 +02:00
Pekka Enberg
f6a16e8299 Add Database.batch() to the JavaScript SDKs
The batch() method executes an array of SQL statements over a single
connection and returns aggregated `rowsAffected` and `lastInsertRowid`. Each
statement is either a SQL string or a `{ sql, args }` object with positional
or named bind parameters; named-args objects are forwarded to the underlying
engine as named parameters rather than collapsed via Object.values().

By default the batch is non-transactional: each statement runs in its own
autocommit step. Passing a `mode` -- `deferred`, `immediate`, `exclusive`, or
`concurrent` -- makes the batch atomic. You can also use `batch()` with the
transaction API to make it transactional.

The serverless driver implements atomic batch as a a single SQL over HTTP
request. The wire payload chains BEGIN, the user statements, COMMIT, and
ROLLBACK as a single batch using the server-side condition operators.
2026-05-19 16:25:07 +03:00
Pekka Enberg
bb6a7d5b78 serverless/javascript: Bump version to 1.0.0 2026-03-26 08:15:51 +02:00
Pekka Enberg
4e144df120 Move @tursodatabase/serverless to serverless/javascript
Reorganize serverless SDKs under a top-level serverless/ directory
to support multi-language serverless drivers alongside the existing
bindings/ convention.
2026-03-26 08:15:10 +02:00