hammerspoon2-docs
    Preparing search index...

    Class DatabaseSync

    A connection to a SQLite database, as Node's DatabaseSync from require('node:sqlite').

    Every method runs synchronously. Databases are opened with foreign key constraints enforced and double-quoted string literals disabled, as in Node.

    Not implemented from Node: function(), aggregate(), loadExtension(), enableLoadExtension(), createSession(), applyChangeset(), backup(), createTagStore() and Symbol.dispose.

    Index
    • Opens a SQLite database.

      Supported options, all optional:

      • open (boolean, default true): open the database now. If false, call open() later.
      • readOnly (boolean, default false): open the database read-only.
      • enableForeignKeyConstraints (boolean, default true): enforce foreign key constraints.
      • enableDoubleQuotedStringLiterals (boolean, default false): accept double-quoted string literals.
      • timeout (integer, default 0): milliseconds to wait for a locked database before failing.
      • readBigInts (boolean, default false): read INTEGER values as BigInts.
      • returnArrays (boolean, default false): return rows as arrays instead of objects.
      • allowBareNamedParameters (boolean, default true): allow named parameters without their prefix character.
      • allowUnknownNamedParameters (boolean, default false): ignore named parameters that the statement doesn't use.

      Statements prepared on this database start with its readBigInts, returnArrays, allowBareNamedParameters and allowUnknownNamedParameters settings.

      Parameters

      • path: string

        The path of the database file, or ":memory:" for an in-memory database. A leading ~ is expanded to the home directory. Relative paths are relative to Hammerspoon's working directory, so use absolute paths.

      • Optionaloptions: Record<string, any>

        The options described above

      Returns DatabaseSync

    isOpen: boolean

    Whether the database is currently open.

    isTransaction: boolean

    Whether the database is inside a transaction. Throws if the database isn't open.

    • Closes the database, finalizing every statement prepared on it. Throws if the database isn't open.

      Returns void

    • Runs one or more SQL statements, without returning any results. Statements run in order until one fails, which throws.

      Parameters

      • sql: string

        The SQL to run

      Returns void

    • The file path of a database attached to this connection.

      Parameters

      • OptionaldbName: string

        The name of the attached database. Defaults to "main".

      Returns string | null

      The path, or null for an in-memory database or an unknown name

    • Opens the database. Only needed if it was constructed with open: false, or after close(). Throws if the database is already open.

      Returns void

    • Compiles a SQL statement so it can be run, any number of times, with different parameters. Only the first statement in sql is compiled.

      Parameters

      • sql: string

        The SQL to compile

      Returns StatementSync

      The prepared statement