Repository navigation
libsql: add Connection::limit and Connection::set_limit - #2305
Open
jeffreykwan wants to merge 1 commit into
Open
jeffreykwan wants to merge 1 commit into
jeffreykwan wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SQLite lets each connection lower its run-time limits with
sqlite3_limit(), for exampleSQLITE_LIMIT_LENGTHto 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, andlibsql::Connectiondoesn'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>andConnection::set_limit(Limit, i32) -> Result<i32>, plus aLimitenum whose values match theSQLITE_LIMIT_*constants. It follows rusqlite'slimit/set_limit:set_limitreturns the previous value, values above the compile-time maximum are capped, and a negative value leaves the limit unchanged. Unlike rusqlite it returnsResult, because remote (Hrana) connections can't support it and return the newError::LimitNotSupported. Embedded replicas and synced databases forward to their local connection.Tests. Integration tests cover lowering
Limit::Length(format()returns NULL andzeroblob()fails withSQLITE_TOOBIGabove the limit), negative values, limits being per connection, and the remote error. A unit test checks the enum values againstlibsql_sys::ffi. The fulllibsqltest suite passes locally.A follow-up libsql-js PR adds
Database.limit()/Database.setLimit()on top of this.🤖 Generated with Claude Code