feat(vfs): add FileControl support for PRAGMA handling - #17
Closed
corylanou wants to merge 5 commits into
Closed
Conversation
Add xFileControl implementation to enable SQLite PRAGMA commands to be handled by VFS implementations. This allows VFS files to respond to custom PRAGMA statements, enabling features like time travel without using SELECT-based state changes. Changes: - Add FileController optional interface in file.go - Implement goVFSFileControl CGO bridge with PRAGMA argument parsing - Update s3vfsFileControl to call Go layer instead of returning NOTFOUND - Handle char** array parsing for pragma name and value - Support result string return via azArg[0] This provides a more semantically correct approach for VFS state management compared to custom SQL functions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Verify that the FileController interface works correctly by testing custom PRAGMA set and query operations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Reverts the module path change to keep compatibility with upstream.
Owner
|
Thanks for the pr! This seems like a reasonable improvement. It looks like the tests are not passing right now though. |
SQLite expects memory returned from FCNTL_PRAGMA to be allocated with sqlite3_malloc so it can be freed with sqlite3_free. Using C.CString (which uses malloc) caused a crash on Linux.
Contributor
Author
|
@psanford whooops! Missed that somehow. Should be fixed. Let me know if you need anything else. |
Owner
|
I cleaned up the git history and merged it. Thank you for the PR! |
This was referenced Nov 27, 2025
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.
Summary
FileControllerinterface for handling file control operationsSQLITE_FCNTL_PRAGMAsupport to enable custom PRAGMA commandsContext
This change addresses the need for custom PRAGMA support in Go-based SQLite VFS implementations, as discussed in benbjohnson/litestream#849.
When implementing time travel queries for Litestream, @asg017 suggested using custom PRAGMAs (e.g.,
PRAGMA litestream_time = '[date]') instead of SQL functions. This approach is cleaner and more suitable for read-only environments like Datasette. However, implementing custom PRAGMAs requires FileControl support in the VFS layer, which was previously unavailable.Changes
New
FileControllerinterface (file.go): Optional interface thatFileimplementations can implement to handle file control operations, specificallySQLITE_FCNTL_PRAGMA.C bridge update (
sqlite3vfs.c):s3vfsFileControlnow delegates to the Go implementation instead of returningSQLITE_NOTFOUND.Go implementation (
sqlite3vfscgo.go):goVFSFileControlhandles PRAGMA operations by:FileControllerinterface if implemented by the fileTests (
sqlite3vfs_test.go,tmpvfs_test.go): Verify PRAGMA set and query operations work correctly.Usage
VFS implementers can now handle custom PRAGMAs by implementing the
FileControllerinterface:Happy to adjust the approach or implementation if you have any preferred direction - just let us know!