Generates the next monotonic integer id for a sharded table.
This replaces the common but broken SELECT COALESCE(MAX(id), 0) + 1 on a
single shard: because rows for a generated id land on the shard the new id
hashes to, a per-shard MAX never sees rows on the other shards and hands out
colliding ids. nextId reads MAX(column) across all shards, then:
If a coordinator is configured, it calls the Durable Object's atomic
sequence (seeded by that cross-shard max), which is race-free across
concurrent callers and isolates. Recommended for production writes.
Otherwise it returns max + 1. This is cross-shard-correct but not
concurrency-safe on its own; pair it with a unique constraint or a
coordinator when multiple writers race.
Generates the next monotonic integer id for a sharded table.
This replaces the common but broken
SELECT COALESCE(MAX(id), 0) + 1on a single shard: because rows for a generated id land on the shard the new id hashes to, a per-shard MAX never sees rows on the other shards and hands out colliding ids.nextIdreadsMAX(column)across all shards, then:max + 1. This is cross-shard-correct but not concurrency-safe on its own; pair it with a unique constraint or a coordinator when multiple writers race.