Skip to content

add URI parameter support via optional URIOpener interface - #18

Closed
corylanou wants to merge 1 commit into
psanford:mainfrom
corylanou:uri-filename-support
Closed

add URI parameter support via optional URIOpener interface#18
corylanou wants to merge 1 commit into
psanford:mainfrom
corylanou:uri-filename-support

Conversation

@corylanou

@corylanou corylanou commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Motivation

Expose SQLite URI parameters to VFS implementations at open time.

I hit this while building Litestream as a SQLite loadable extension + VFS. When a user loads a VFS extension and opens a database with URI parameters, for example:

.load ./litestream
ATTACH 'file:app.db?vfs=litestream&poll_interval=5s' AS db;

The VFS needs those params during xOpen to initialize the connection. Environment variables are process-wide, PRAGMAs run after open, and SQLite URI parameters are the per-connection mechanism available during xOpen.

Relevant downstream issues: benbjohnson/litestream#1150 and benbjohnson/litestream#1231.

Changes

Adds an optional interface:

type URIOpener interface {
    OpenURI(name string, params map[string]string, flags OpenFlag) (File, OpenFlag, error)
}

When a registered VFS implements URIOpener, the cgo bridge reads the URI parameters from SQLite's filename pointer using sqlite3_uri_key() and sqlite3_uri_parameter(), then calls OpenURI. Existing VFS implementations continue to use Open unchanged.

defaultVFSv1 forwards OpenURI to wrapped VFS values that implement URIOpener, so callers can register a plain VFS that optionally implements the URI-aware method.

Tests

TestURIOpener registers a capturing VFS, opens file:test.db?vfs=...&poll_interval=5s&cache_size=128, and verifies that OpenURI receives the filename and URI parameter map.

Verified with:

go test -race ./...

corylanou added a commit to benbjohnson/litestream that referenced this pull request Apr 21, 2026
Replace the internal sqlite3vfs fork with the upstream module import and a temporary replace to the URI-support branch from psanford/sqlite3vfs#18.

Add an end-to-end URI replica_url test and keep test fault injection active for FilenameOpener-based opens.
@psanford

Copy link
Copy Markdown
Owner

I am fine with doing this conceptually, but this pr is a bit of a mess. It looks like you asked claude-code to implement this and threw a pr up with no real thought about it.

A reasonable interface would probably look more like:

type URIOpener interface {
    OpenURI(name string, params map[string]string, flags OpenFlags) (File, OpenFlag, error)
}

If you are going to use claude-code at least use a new session to critique the pr before you submit it.

@corylanou
corylanou force-pushed the uri-filename-support branch from a9ece85 to bcabaf2 Compare April 30, 2026 14:29
@corylanou corylanou changed the title add URI parameter support via optional FilenameOpener interface add URI parameter support via optional URIOpener interface Apr 30, 2026
@corylanou

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. I reworked this around the narrower URIOpener interface shape you suggested, removed the Filename wrapper and the unrelated test-helper cleanup, and force-pushed the branch as a single focused commit. I also updated the PR description to match the current diff.\n\nVerified locally with go test -race ./...; the GitHub stable and oldstable checks are green now too.

@corylanou
corylanou force-pushed the uri-filename-support branch from bcabaf2 to 583d6e6 Compare April 30, 2026 14:33
@corylanou

Copy link
Copy Markdown
Contributor Author

Hi @psanford just following up to get your thoughts on this last change? Thanks again for all your work on this repo!

corylanou added a commit to benbjohnson/litestream that referenced this pull request May 18, 2026
Switches the pseudo-version pin to the tagged v0.1.0 release on
corylanou/sqlite3vfs so the dependency remains reachable if the
uri-filename-support branch is deleted (e.g. when psanford/sqlite3vfs#18
lands upstream and the source branch is cleaned up).

When the upstream PR merges, drop the replace directive and update the
require to the upstream tag/pseudo-version.
corylanou added a commit to benbjohnson/litestream that referenced this pull request May 18, 2026
Replace the internal sqlite3vfs fork with the upstream module import and a temporary replace to the URI-support branch from psanford/sqlite3vfs#18.

Add an end-to-end URI replica_url test and keep test fault injection active for FilenameOpener-based opens.
corylanou added a commit to benbjohnson/litestream that referenced this pull request May 18, 2026
Switches the pseudo-version pin to the tagged v0.1.0 release on
corylanou/sqlite3vfs so the dependency remains reachable if the
uri-filename-support branch is deleted (e.g. when psanford/sqlite3vfs#18
lands upstream and the source branch is cleaned up).

When the upstream PR merges, drop the replace directive and update the
require to the upstream tag/pseudo-version.
@psanford psanford closed this in f9180fa May 19, 2026
@psanford

Copy link
Copy Markdown
Owner

Thanks for fixing this up!

corylanou added a commit to benbjohnson/litestream that referenced this pull request Jul 27, 2026
Replace the internal sqlite3vfs fork with the upstream module import and a temporary replace to the URI-support branch from psanford/sqlite3vfs#18.

Add an end-to-end URI replica_url test and keep test fault injection active for FilenameOpener-based opens.
corylanou added a commit to benbjohnson/litestream that referenced this pull request Jul 27, 2026
Switches the pseudo-version pin to the tagged v0.1.0 release on
corylanou/sqlite3vfs so the dependency remains reachable if the
uri-filename-support branch is deleted (e.g. when psanford/sqlite3vfs#18
lands upstream and the source branch is cleaned up).

When the upstream PR merges, drop the replace directive and update the
require to the upstream tag/pseudo-version.
corylanou added a commit to benbjohnson/litestream that referenced this pull request Aug 3, 2026
Replace the internal sqlite3vfs fork with the upstream module import and a temporary replace to the URI-support branch from psanford/sqlite3vfs#18.

Add an end-to-end URI replica_url test and keep test fault injection active for FilenameOpener-based opens.
corylanou added a commit to benbjohnson/litestream that referenced this pull request Aug 3, 2026
Switches the pseudo-version pin to the tagged v0.1.0 release on
corylanou/sqlite3vfs so the dependency remains reachable if the
uri-filename-support branch is deleted (e.g. when psanford/sqlite3vfs#18
lands upstream and the source branch is cleaned up).

When the upstream PR merges, drop the replace directive and update the
require to the upstream tag/pseudo-version.
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.

2 participants