@photostructure/sqlite
    Preparing search index...

    Interface EnhancedStatementMethods

    A statement enhanced with better-sqlite3-style .pluck(), .raw(), and .expand() methods. These are mutually exclusive — enabling one disables the others.

    interface EnhancedStatementMethods {
        database: EnhanceableDatabaseSync;
        expand(toggle?: boolean): this;
        pluck(toggle?: boolean): this;
        raw(toggle?: boolean): this;
    }
    Index

    Properties

    Methods

    Properties

    The database instance this statement was prepared from.

    Methods

    • Causes the statement to return data namespaced by table. Each key in a row object will be a table name, and each corresponding value will be a nested object containing that table's columns. Columns from expressions or subqueries are placed under the special $ namespace.

      When expand mode is turned on, pluck and raw modes are turned off.

      Requires the statement to have a .columns() method (available on real statements but not minimal mocks).

      Parameters

      • Optionaltoggle: boolean

        Enable (true) or disable (false) expand mode. Defaults to true.

      Returns this

      The same statement for chaining.

      const rows = db.prepare("SELECT u.id, u.name, p.title FROM users u JOIN posts p ON ...").expand().all();
      // Returns: [{ users: { id: 1, name: "Alice" }, posts: { title: "Hello" } }]
    • Causes the statement to return only the first column value of each row.

      When plucking is turned on, raw and expand modes are turned off.

      Parameters

      • Optionaltoggle: boolean

        Enable (true) or disable (false) pluck mode. Defaults to true.

      Returns this

      The same statement for chaining.

      const count = db.prepare("SELECT COUNT(*) FROM users").pluck().get();
      // Returns: 42 (not { "COUNT(*)": 42 })

      const names = db.prepare("SELECT name FROM users").pluck().all();
      // Returns: ["Alice", "Bob"] (not [{ name: "Alice" }, { name: "Bob" }])
    • Causes the statement to return rows as arrays of values instead of objects.

      When raw mode is turned on, pluck and expand modes are turned off.

      Parameters

      • Optionaltoggle: boolean

        Enable (true) or disable (false) raw mode. Defaults to true.

      Returns this

      The same statement for chaining.

      const rows = db.prepare("SELECT id, name FROM users").raw().all();
      // Returns: [[1, "Alice"], [2, "Bob"]] (not [{ id: 1, name: "Alice" }, ...])