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

URI schemed database names are interpreted as files #1675

Open
bfraterman-tkhsecurity opened this issue Jan 25, 2023 · 2 comments
Open

URI schemed database names are interpreted as files #1675

bfraterman-tkhsecurity opened this issue Jan 25, 2023 · 2 comments
Labels

Comments

@bfraterman-tkhsecurity
Copy link

Issue Summary

When passing a database name in the form of a URI, this is interpreted as file, while it could also be an in-memory database. SQLite defines the URI scheme it uses here: https://www.sqlite.org/uri.html

So for example, this will give an error (since the file name :memory: usually can't be created on a filesystem) when trying to create a database:

new sqlite3.Database("file::memory:?cache=shared");

While it's supposed to create an in-memory database with shared cache.

Also if you want to use a named in-memory database (for use with multiple connections), you should be able to do this:

new sqlite3.Database("file:memdb1?mode=memory&cache=shared");

But this actually creates a file on the file system named file. On Windows there's even the particularity that this becomes a file with alternate data stream (since there's a : in the file name) and the data will be stored in the ADS. Very confusing at first.

The line causing this problem is here: https://github.com/TryGhost/node-sqlite3/blob/master/lib/sqlite3.js#L31

Steps to Reproduce

Try: new sqlite3.Database("file::memory:?cache=shared"); this will give an error.
Try: new sqlite3.Database("file:memdb1?mode=memory&cache=shared");. This will create a file (on Windows) instead of opening the database in-memory.

Version

5.1.2

Node.js Version

v14.18.2

How did you install the library?

Windows, npm install, library is used through TypeORM

@piotr-cz
Copy link

More examples may be found here:
SQLite > In-memory Databases And Shared Cache

@jakolehm
Copy link

@bfraterman-tkhsecurity I was facing the same issue but then realized that an URI requires a different mode. Following should work:

new sqlite3.Database("file:memdb1?mode=memory&cache=shared", OPEN_READWRITE | OPEN_CREATE | OPEN_FULLMUTEX | OPEN_URI)

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

No branches or pull requests

3 participants