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

Serialization -> Deserialization doesn't seem to be working #1291

Open
lukeschaefer opened this issue Nov 15, 2024 · 2 comments
Open

Serialization -> Deserialization doesn't seem to be working #1291

lukeschaefer opened this issue Nov 15, 2024 · 2 comments

Comments

@lukeschaefer
Copy link

For performance reasons, I'd like to do a number of large operations in memory, rather than interacting with the disk. This succeeds in creating an in-memory db: const db = new Database(':memory:');

However if I want to take an existing db and fully bring it into memory, this fails:

const db = new Database("./snapshot.db");
const buffer = db.serialize();
const inMemoryDb = new Database(buffer);
// Failure occurs on the next line:
inMemoryDb.prepare("SELECT phrase FROM Phrases");

I get SqliteError: unable to open database file. I can confirm the buffer is filled with data that can be written to disk and loaded via the filesystem like usual. But creating a Database out of a buffer seems to always result in a failure.

@Prinzhorn
Copy link
Contributor

Cannot reproduce with the latest better-sqlite3:

import Database from 'better-sqlite3'

const db = new Database('./Chinook_Sqlite.sqlite');
const buffer = db.serialize();
const inMemoryDb = new Database(buffer);
const stmt = inMemoryDb.prepare('SELECT Name FROM Artist');
console.log(stmt.all());

With database downloaded from https://github.com/lerocha/chinook-database/releases

You're likely using WAL, see #1066 (comment) and #939 (comment)

@JoshuaWise maybe serialize could detect that and throw a more descriptive error? At least the docs should be updated.

@lukeschaefer
Copy link
Author

lukeschaefer commented Nov 15, 2024

You're likely using WAL

Yup, you're dead on, thanks for the quick assessment. Rebuilding the DB without using WAL fixed the issue.

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