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 AUTOINCREMENT or SERIAL sequence, so spreading a
generated-key table across shards eventually mints the same id twice. When
that happens this throws GENERATED_KEY_COLLISION rather 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.
Type Parameters
T = Record<string,unknown>
Type of returned rows when the insert uses RETURNING
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.