Skip to content

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

Open
jeffreykwan wants to merge 1 commit into
tursodatabase:mainfrom
jeffreykwan:jk-connection-limits
Open

jeffreykwan wants to merge 1 commit into
tursodatabase:mainfrom
jeffreykwan:jk-connection-limits

Conversation

@jeffreykwan

Copy link
Copy Markdown

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>

This branch has not been deployed

No deployments
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.

1 participant