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.

      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: {
            allowBareNamedParameters?: boolean;
            allowUnknownNamedParameters?: boolean;
            enableDoubleQuotedStringLiterals?: boolean;
            enableForeignKeyConstraints?: boolean;
            open?: boolean;
            readBigInts?: boolean;
            readOnly?: boolean;
            returnArrays?: boolean;
            timeout?: number;
        }

        How to open the database

        • OptionalallowBareNamedParameters?: boolean

          Allow named parameters without their prefix character. Defaults to true

        • OptionalallowUnknownNamedParameters?: boolean

          Ignore named parameters that the statement doesn't use. Defaults to false

        • OptionalenableDoubleQuotedStringLiterals?: boolean

          Accept double-quoted string literals. Defaults to false

        • OptionalenableForeignKeyConstraints?: boolean

          Enforce foreign key constraints. Defaults to true

        • Optionalopen?: boolean

          Open the database now. If false, call open() later. Defaults to true

        • OptionalreadBigInts?: boolean

          Read INTEGER values as BigInts. Defaults to false

        • OptionalreadOnly?: boolean

          Open the database read-only. Defaults to false

        • OptionalreturnArrays?: boolean

          Return rows as arrays instead of objects. Defaults to false

        • Optionaltimeout?: number

          Milliseconds to wait for a locked database before failing. Defaults to 0

      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