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.
The result, merged across shards when the statement routes to several
Throws
If the routing key cannot be determined and onUnroutable is throw
Since
1.4.0
Example
awaitquery('INSERT INTO users (id, name) VALUES (?, ?)', ['user-1', 'Ada']); awaitquery('UPDATE users SET name = ? WHERE id = ?', ['Ada L.', 'user-1']); awaitquery('DELETE FROM users WHERE id IN (?, ?)', ['user-1', 'user-2']);
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 asrun('user-1', ...)would.Recognized shapes are
INSERT INTO t (cols) VALUES (...)including multi-row inserts, andUPDATE/DELETE/SELECTwhose entireWHEREclause iskey = ?orkey IN (?, ?, ...). The key column comes fromkeyColumnsin the configuration and defaults toid.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.