I recently changed some code I have using SQLite via better-sqlite3 to check if a table exists before running certain import queries.
The code and tests all run fine. But the tests don't pass on our build machines or on another developers machine. The tests are using an in-memory database, the problem hasn't occurred on any non-memory databases though it has only been ran on a half-dozen machines. There are tables in the database and code is able to read/write to them.
It turns out that the query I was using to check what tables I can import from was return an empty result. In fact, if I just query anything at all from sql_master in these cases I get an empty result.
// db is a database from better-sqlite3
private async getAllTables() {
var query = connection.db.prepare(`SELECT name, type FROM sqlite_master`).raw();
return query.all();
}
var allTables = await this.getAllTables();
console.log(`all things in sql_master: ${await allTables.join(", ")}.`);
The console has the following logged on the problematic matchines:
All things in sql_master: .
Locally it prints a list of all the things in sql_master as you'd expected. All the other queries my test code is doing is working as expected (reading and writing to tables besides sql_master).
The database was created like:
db = new Connection(":memory:", { memory: true, fileMustExist: true });