Skip to content

Open existing db in memory mode #936

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

Closed
Mythli opened this issue Jan 9, 2023 · 2 comments
Closed

Open existing db in memory mode #936

Mythli opened this issue Jan 9, 2023 · 2 comments

Comments

@Mythli
Copy link

Mythli commented Jan 9, 2023

Dear better-sqlite3 contributors,

Thank you for the amazing library. Your effort has enabled uncountable amazing products to be build that are faster than without this library.

For integration testing I would like to open an existing database file in memory mode, so that further changes are not persisted. Is such a thing possible?

sqlite(process.env.database, {memory: true}),

gives me the error TypeError: Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)

I can use the :memory: file string but then all migrations and seeders need to be re-run which slows down the tests considerably.
I also tried test.sqlite3?mode=memory&cache=shared but this just creates a db with the connection string as name.

@Prinzhorn
Copy link
Contributor

  1. Read file as buffer
  2. Pass buffer to new Database(buf)

I also tried test.sqlite3?mode=memory&cache=shared but this just creates a db with the connection string as name.

See #483

@Mythli
Copy link
Author

Mythli commented Jan 9, 2023

Danke, 10/10 // Thanks, 10/10!

@Mythli Mythli closed this as completed Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants