better-sqlite3
better-sqlite3 copied to clipboard
File is not a database.
Environment: macOS I have a database that is encrypted named 'test.data'. I want read this data
import Database from "better-sqlite3";
const db = new Database("/test.data");
// This key is correct
db.pragma(`key = 'cc8e3387ec19bc2f73b35ebdfa9d9b3f'`);
db.exec(
"ATTACH DATABASE '/test.db' AS encrypted KEY '';"
);
db.pragma(key = 'cc8e3387ec19bc2f73b35ebdfa9d9b3f');
This line can be executed.
db.exec(
"ATTACH DATABASE '/test.db' AS encrypted KEY '';"
);
This line will not be executed. it throw an error: SqliteError: file is not a database I don't know how to read this database. Thanks for your help
Are you sure you have both a test.data and a test.db file in the root of your file system?
Also SQLite does not have a key pragma (see list here https://www.sqlite.org/pragma.html). You probably want to load some sort of extension like SQLCipher. I think there are better-sqlite3 forks out there with it built-in.