feat(plugin-libsql): open local libSQL database files from the connection form#1610
Conversation
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 36b2307df7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| while sqlite3_step(statement) == SQLITE_ROW { | ||
| if rows.count >= PluginRowLimits.emergencyMax { | ||
| truncated = true | ||
| break | ||
| } | ||
| rows.append(rowValues(of: statement, count: columnCount)) | ||
| } |
There was a problem hiding this comment.
Report sqlite3_step failures for local statements
In local libSQL mode, DML errors are returned from sqlite3_step, not sqlite3_prepare_v2; for example a UNIQUE/CHECK/FK violation, SQLITE_BUSY, or disk I/O error makes this loop exit with a non-SQLITE_ROW result and then fall through as a successful query. That means data edits can be reported as saved even though SQLite rejected them, so please capture the final step result and throw unless it is SQLITE_DONE (apart from the intentional truncation path).
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: df52bae4c5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let localBackend = SQLiteLocalBackend() | ||
| try await localBackend.open(path: path) | ||
| let rawHandle = await localBackend.dbHandleForInterrupt | ||
| let versionResult = try await localBackend.executeQuery("SELECT sqlite_version()") |
There was a problem hiding this comment.
Validate the selected file by reading the database schema
In local mode, this connection test can accept corrupt, encrypted, or non-SQLite files because SELECT sqlite_version() only returns the SQLite library version and does not read the database file; for example, the same handle will succeed here but fail on PRAGMA schema_version/sqlite_master with "file is not a database". This means Test Connection/Save can report success for an unusable local libSQL file, and the first sidebar/schema load then fails instead.
Useful? React with 👍 / 👎.
| var batch: [PluginRow] = [] | ||
| batch.reserveCapacity(batchSize) | ||
|
|
||
| while sqlite3_step(statement) == SQLITE_ROW { |
There was a problem hiding this comment.
Report step failures while streaming local rows
When exporting or otherwise streaming a local libSQL query, any sqlite3_step result other than SQLITE_ROW exits this loop and finishes the stream successfully. If SQLite returns SQLITE_BUSY, SQLITE_IOERR, or SQLITE_INTERRUPT after partial rows, the export/query stream is presented as complete instead of failed, so please retain the final step result and finish with an error unless it is SQLITE_DONE.
Useful? React with 👍 / 👎.
Closes #1607.
Problem
The libSQL / Turso plugin only connects to remote databases over the Hrana HTTP protocol. There is no way to open a local libSQL database file, even though unencrypted libSQL files use the standard SQLite file format.
Change
One libSQL connection type, two backends:
Compatibility
Tests
Release note
After merge, tag plugin-libsql-v1.1.0 to publish the updated binary to the registry. Bundled plugins are unaffected.