Skip to content

libsql: add Connection::limit and Connection::set_limit - #2305

Merged
penberg merged 1 commit into
tursodatabase:mainfrom
jeffreykwan:jk-connection-limits
Nov 7, 2026
Merged

penberg merged 1 commit into
tursodatabase:mainfrom
jeffreykwan:jk-connection-limits

Conversation

@jeffreykwan

Copy link
Copy Markdown
Contributor

SQLite lets each connection lower its run-time limits with sqlite3_limit(), for example SQLITE_LIMIT_LENGTH to cap the size of any string or BLOB a query can build. There is no PRAGMA for most of these, so callers need native access, and libsql::Connection doesn't expose it today. We'd like to use this from libsql-js to stop a single query from allocating a huge value in memory.

API. This adds Connection::limit(Limit) -> Result<i32> and Connection::set_limit(Limit, i32) -> Result<i32>, plus a Limit enum whose values match the SQLITE_LIMIT_* constants. It follows rusqlite's limit / set_limit: set_limit returns the previous value, values above the compile-time maximum are capped, and a negative value leaves the limit unchanged. Unlike rusqlite it returns Result, because remote (Hrana) connections can't support it and return the new Error::LimitNotSupported. Embedded replicas and synced databases forward to their local connection.

Tests. Integration tests cover lowering Limit::Length (format() returns NULL and zeroblob() fails with SQLITE_TOOBIG above the limit), negative values, limits being per connection, and the remote error. A unit test checks the enum values against libsql_sys::ffi. The full libsql test suite passes locally.

A follow-up libsql-js PR adds Database.limit() / Database.setLimit() on top of this.

🤖 Generated with Claude Code

Expose sqlite3_limit so callers can read and lower per-connection
run-time limits, such as SQLITE_LIMIT_LENGTH. The API follows rusqlite's
limit and set_limit, but returns Result because remote connections
can't support it; they return Error::LimitNotSupported. Embedded
replicas and synced databases forward to their local connection.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@penberg

penberg commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

@claude review

@penberg
penberg merged commit a1d031c into tursodatabase:main Nov 7, 2026
19 checks passed
@jeffreykwan
jeffreykwan deleted the jk-connection-limits branch November 9, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants