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

    Constructors

    • Opens a SQLite database. 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

    Properties

    isOpen: boolean

    Whether the database is currently open.

    isTransaction: boolean

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

    Methods

    • 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