@earth-app/collegedb
    Preparing search index...

    Function query

    • Executes a statement, taking the routing key from the statement itself.

      This is run without the duplicated key argument. The planner reads the primary key out of the statement, so query('INSERT INTO users (id, name) VALUES (?, ?)', ['user-1', 'Ada']) routes exactly as run('user-1', ...) would.

      Recognized shapes are INSERT INTO t (cols) VALUES (...) including multi-row inserts, and UPDATE/DELETE/SELECT whose entire WHERE clause is key = ? or key IN (?, ?, ...). The key column comes from keyColumns in the configuration and defaults to id.

      A statement whose key cannot be proven is not guessed at. By default it throws and names the explicit-key alternative; set onUnroutable: 'fanout' to run it on every shard instead.

      A statement that resolves to several keys is grouped by shard and executed with one round trip per shard, so WHERE id IN (...) spanning three shards is three statements rather than one per id.

      Type Parameters

      • T = Record<string, unknown>

        Type of the result records

      Parameters

      • sql: string

        Statement text using ? placeholders

      • bindings: any[] = []

        Positional bindings for the statement

      Returns Promise<QueryResult<T>>

      The result, merged across shards when the statement routes to several

      If the routing key cannot be determined and onUnroutable is throw

      1.4.0

      await query('INSERT INTO users (id, name) VALUES (?, ?)', ['user-1', 'Ada']);
      await query('UPDATE users SET name = ? WHERE id = ?', ['Ada L.', 'user-1']);
      await query('DELETE FROM users WHERE id IN (?, ?)', ['user-1', 'user-2']);