Type of returned rows when the insert uses RETURNING
The INSERT statement to execute
Parameter values to bind to the statement
idColumn names the generated key column, table enables cleanup of a refused row
Promise resolving to the write result plus the generated id
Executes an insert on an automatically selected shard and returns the generated primary key.
This is the default helper for generated-key tables. CollegeDB picks a shard using the configured allocation strategy, then stores the generated primary key -> shard mapping so routed reads can find the row later.
A database-generated id is only unique within its own shard. Every shard runs its own
AUTOINCREMENTorSERIALsequence, so spreading a generated-key table across shards eventually mints the same id twice. When that happens this throwsGENERATED_KEY_COLLISIONrather than overwriting the first mapping and stranding its row. For a generated-key table that spans shards, allocate the id with nextId and pass it explicitly; to keep using the database's own sequence, confine the table to one shard with insertShard.The refused row. The INSERT has already run when the collision shows up. CollegeDB takes only a raw SQL string here and does not parse it, so it does not know which table to clean. Pass
options.tableand it deletes the row it just wrote (matched onidColumn, defaultid) before it throws. Withouttablethe row stays on the shard and removing it is the caller's job; the error message names the shard and id. If the delete itself fails, the error still has the codeGENERATED_KEY_COLLISION, names the shard and id of the leftover row, and carries the delete failure ascause.