Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support passing file:// URI when using custom-compile SQLite #1106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aslushnikov
Copy link

I'm trying to use better-sqlite3 with an SQLite that is compiled with SQLITE_USE_URI=1:

const db = SQLite(`file:///foo/bar?vfs=myfs&mode=ro&immutable=1`);

This, however, doesn't work right now, since there's an erroneous assertion in the database creation.

With this patch, I can successfully connect to the database.

References #483

…E_USE_URI=1`

I'm trying to use `better-sqlite3` with an SQLite that is compiled with
`SQLITE_USE_URI=1`:

```js
const db = SQLite(`file:///foo/bar?vfs=myfs&mode=ro&immutable=1`);
```

This, however, doesn't work right now, since there's an erroneous
assertion in the database creation.

With this patch, I can successfully connect to database.

References WiseLibs#483
@Prinzhorn
Copy link
Contributor

Prinzhorn commented Nov 20, 2023

It might solve your problem in a hacky way but it does not feel like the correct solution since these things are not mutually exclusive. Checking if the directory exists makes sense regardless if you're using file:// or not.

> require('url').fileURLToPath('file:///foo/bar?vfs=myfs&mode=ro&immutable=1')
'/foo/bar'

I don't know what the right solution is, but I feel like the current logic conflicts with the use of file://. E.g. it allows some of the options like readonly. So there needs to be a "UR mode" that forbids other options or does some more sanity checks.

@aslushnikov
Copy link
Author

I don't know what the right solution is, but I feel like the current logic conflicts with the use of file://. E.g. it allows some of the options like readonly. So there needs to be a "UR mode" that forbids other options or does some more sanity checks.

@Prinzhorn I agree that proper URI support would need to address these points, and this is discussed to some extend in #483

However, some of the extensions actually rely on the "fake URI", like this one: https://github.com/mlin/sqlite_web_vfs:

const db = SQLite(`file:///__web__?vfs=web&mode=ro&immutable=1&web_uri=${encodeURIComponent(dbUrl)}`);

Do you think it'd be possible to have some escape hatch for these kind of use cases?

Thank you for your review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants