hammerspoon2-docs
    Preparing search index...

    Class StatementSync

    A prepared statement, as Node's StatementSync. Made by DatabaseSync.prepare(); it can't be constructed directly.

    Parameters are bound the same way for run(), get(), all() and iterate(): if the first argument is an object (other than a typed array), its properties are bound to named parameters (:name, @name or $name), and any remaining arguments are bound, in order, to anonymous (?) parameters. Values convert as in Node:

    JavaScript SQLite
    null, undefined NULL
    number REAL (stored as INTEGER in columns with INTEGER affinity)
    boolean INTEGER 1 or 0
    bigint INTEGER
    string TEXT
    typed array (e.g. Uint8Array) BLOB

    Results come back as null, numbers (or BigInts, see setReadBigInts()), strings and Uint8Arrays. An INTEGER too large to be a JS number throws, unless readBigInts is set.

    Index
    expandedSQL: string | null

    The statement's SQL, with each parameter replaced by the value most recently bound to it.

    sourceSQL: string | null

    The statement's SQL, as passed to prepare().

    • Runs the statement and returns all of its rows.

      Parameters

      • ...params: any[]

        Named parameters (an object) and/or anonymous parameters

      Returns any[]

      The rows, each an object keyed by column name (or an array, if returnArrays is set)

    • Describes the columns the statement returns.

      Returns {
          column: string | null;
          database: string | null;
          name: string;
          table: string | null;
          type: string | null;
      }[]

      One object per column: its name in the result (name), and, for a column read directly from a table, the original column name, database, table and declared type

    • Runs the statement and returns its first row.

      Parameters

      • ...params: any[]

        Named parameters (an object) and/or anonymous parameters

      Returns any

      The first row, as an object keyed by column name (or an array, if returnArrays is set), or undefined if there are no rows

    • Runs the statement and returns an iterator over its rows, which are read as the iterator is advanced. Running the statement again invalidates the iterator.

      Parameters

      • ...params: any[]

        Named parameters (an object) and/or anonymous parameters

      Returns IterableIterator<any>

      An iterator over the rows

    • Runs the statement, and returns the number of rows it changed and the ID of the last row inserted.

      Parameters

      • ...params: any[]

        Named parameters (an object) and/or anonymous parameters

      Returns { changes: number | bigint; lastInsertRowid: number | bigint }

      The rows changed and the last inserted row ID. These are BigInts if readBigInts is set.

    • Sets whether named parameters may be given without their prefix character ({ id: 1 } for :id).

      Parameters

      • enabled: boolean

        Whether to allow bare names

      Returns void

    • Sets whether named parameters the statement doesn't use are ignored, rather than throwing.

      Parameters

      • enabled: boolean

        Whether to ignore unknown names

      Returns void

    • Sets whether INTEGER values are read as BigInts, including run()'s changes and lastInsertRowid.

      Parameters

      • enabled: boolean

        Whether to read BigInts

      Returns void

    • Sets whether rows are returned as arrays of values instead of objects.

      Parameters

      • enabled: boolean

        Whether to return arrays

      Returns void