Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fileMustExist: true not being respected #5986

@dan-2019

Description

@dan-2019

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
}

  1. When the database path and the database itself exist, everything works as expected.

  2. 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."

  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions