Repository navigation
Add Database.limit() and Database.setLimit() - #246
Draft
jeffreykwan wants to merge 1 commit into
Draft
jeffreykwan wants to merge 1 commit into
jeffreykwan wants to merge 1 commit into
Conversation
Expose SQLite's per-connection run-time limits so callers can, for example, cap SQLITE_LIMIT_LENGTH and stop a single query from building a huge string or BLOB. Adds a Limit constants object that matches the SQLITE_LIMIT_* values. setLimit() returns the previous value. Requires libsql's Connection::limit and Connection::set_limit. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Depends on tursodatabase/libsql#2305, which adds
Connection::limitandConnection::set_limitto thelibsqlcrate. This stays a draft until that change is in a release; then I'll bump thelibsqlversion here. CI will fail until then because the new API isn't on crates.io yet.We run user-written SQL through libsql-js and want to cap how large a single string or BLOB can get, so one query can't allocate a huge value. SQLite supports this per connection with
sqlite3_limit(SQLITE_LIMIT_LENGTH, ...), but there's no PRAGMA for it, so it has to be exposed natively.API.
db.limit(id)returns the current value anddb.setLimit(id, value)sets a new one and returns the previous value, in both the sync (compat.js) and promise (promise.js) APIs. A newLimitobject holds theSQLITE_LIMIT_*constants (Limit.LENGTH,Limit.SQL_LENGTH, ...). Invalid IDs throw, and calling either on a closed database throws the usual closed-database error. Docs are indocs/api.md.Testing. New tests in
extensions.test.jsandasync.test.jscover loweringLimit.LENGTH, negative values, invalid IDs, and use after close. I ran the full integration suite locally against the libsql branch and it passes. In a local check, a query askingformat()for a 500 MB string peaked at about 520 MB RSS without a limit, and about 47 MB with a 4 MBLimit.LENGTH, where it returnsNULLright away.🤖 Generated with Claude Code