interface

sqlite.DatabaseOptions

interface DatabaseOptions

Options for Database

  • create?: boolean

    Allow creating a new database

    Equivalent to constants.SQLITE_OPEN_CREATE

    When false, opening a file that does not exist throws an error with the code SQLITE_CANTOPEN.

  • readonly?: boolean

    Open the database as read-only (no write operations, no create).

    Equivalent to constants.SQLITE_OPEN_READONLY

    Together with create: true or readwrite: true, the constructor throws a TypeError.

  • readwrite?: boolean

    Open the database as read-write

    Equivalent to constants.SQLITE_OPEN_READWRITE

    readwrite: true without create: true does not create the file. readwrite: false is the same as readonly: true.

  • safeIntegers?: boolean

    When true, integers are returned as bigint.

    When false, integers are returned as number, and integers beyond 53 bits are rounded to the nearest number.

    When true, a bigint parameter that does not fit in a signed 64-bit integer throws a RangeError. When false, it keeps its low 64 bits: 2n ** 64n - 1n is stored as -1.

  • strict?: boolean

    When set to true, a query with a missing bound parameter throws an error. When set to false or undefined, the parameter is NULL.

    In both modes, the key of a named parameter can include the $, :, or @ prefix or leave it out. If an object has both keys, the key without the prefix wins in strict mode, and the key with the prefix otherwise.

    const db = new Database(":memory:", { strict: true });
    db.run("INSERT INTO foo (name) VALUES ($name)", { name: "foo" });
    db.run("INSERT INTO foo (name) VALUES ($name)", { nmae: "foo" }); // throws