-
Couldn't load subscription status.
- Fork 2.2k
Description
I am using knex version 2.4.2 in combination with better-sqlite3.
Knex is instantiated with the following configuration:
const knexConfig = {
client: 'better-sqlite3',
connection: {
filename: 'path to non existing db',
options: {
fileMustExist: true,
readonly: false,
verbose: true
},
},
useNullAsDefault: true,
debug: true
}
-
When the database path and the database itself exist, everything works as expected.
-
When the path leading to the database does not exist, upon the first query (not knex instantiation), I receive the error: "TypeError: Cannot open the database because the directory does not exist."
-
When the path leading to the database exists, upon the first query (a zero-byte) database file is created, and I receive a "... no such table" error for my select query.
In cases 2 and 3, I expected to receive an error informing me that the database file must exist, but instead, I see that the program tries to create the file, and the errors are related to its inability to do so or the consequences of the query not being able to access the data because the database is empty.
Is this a bug?
Additionally, it seems that the database opening is only done at the first query and not at knex instantiation. For fileMustExist, this could be tested earlier during initialization, which, in my opinion, would be a more logical place to verify if the database is present, rather than at a later point in the program.