Configuration the client routes with
The client
Same as createSchema.
Same as getClosestRegionFromIP.
Same as all, on this client.
Optionaloptions: ReadOptionsSame as allAllShards, on this client.
Optionaloptions: ReadOptionsSame as allAllShardsGlobal, on this client.
Same as allByLookupKey, on this client.
Optionaloptions: ReadOptionsSame as allShard, on this client.
Optionaloptions: ReadOptionsSame as batch, on this client.
Same as cached, reading and writing this client's KV store unless options.kv is set.
Same as count, on this client.
Optionaloptions: ReadOptionsSame as countAllShards, on this client.
Optionaloptions: ReadOptionsSame as countShard, on this client.
Optionaloptions: ReadOptionsSame as deleteById, on this client.
Same as deleteLookup, on this client.
Same as deleteRow, on this client.
Same as ensureSchema, on this client.
Same as explain, on this client.
Same as explainAllShards, on this client.
Same as explainShard, on this client.
Same as first, on this client.
Optionaloptions: ReadOptionsSame as firstAllShards, on this client.
Optionaloptions: ReadOptionsSame as firstAllShardsGlobal, on this client.
Same as firstByLookupKey, on this client.
Optionaloptions: ReadOptionsSame as firstResilient, on this client.
Optionaloptions: ReadOptionsSame as firstShard, on this client.
Optionaloptions: ReadOptionsSame as flush, on this client.
Same as getActiveConfig, on this client.
Same as getDatabaseSizeForShard, on this client.
Same as getDatabaseSizesAllShards, on this client.
Same as getLookup, on this client.
Same as getMigrationStatus, on this client.
Optionaltable: stringSame as getShardStats, on this client.
Same as getTotalDatabaseSize, on this client.
Same as index, on this client.
Same as indexAllShards, on this client.
Same as indexShard, on this client.
Same as initializeFromEnv, on this client.
Same as insert, on this client.
Same as insertInto, on this client.
Same as insertReturning, on this client.
Same as insertShard, on this client.
Same as invalidate, on this client's KV store unless options.kv is set.
Same as invalidateMappingCache, on this client.
Optionalkey: stringSame as isInitialized, on this client.
Same as listKnownShards, on this client.
Same as nextId, on this client.
Same as paginate, on this client.
Same as patch, on this client.
Same as prepare, on this client.
Same as publishEligibility, on this client.
Same as purgeRetired, on this client.
Same as query, on this client.
Same as queryAll, on this client.
Optionaloptions: ReadOptionsSame as queryFirst, on this client.
Optionaloptions: ReadOptionsSame as reassignShard, on this client.
Same as rebalance, on this client.
Same as reconcileAllocations, on this client's coordinator and placement cache.
Same as recoverMigrations, on this client.
Same as resetConfig, on this client.
Same as run, on this client.
Same as runAllShards, on this client.
Same as runShard, on this client.
Same as setLookup, on this client.
Same as updateRow, on this client.
Same as upsert, on this client.
Same as verifyMigrations, on this client.
const tenantA = createClient({ kv: env.KV_A, shards: { 'db-a1': env.DB_A1, 'db-a2': env.DB_A2 } });
const tenantB = createClient({ kv: env.KV_B, shards: { 'db-b1': env.DB_B1 } });
await Promise.all([tenantA.run('user-1', 'INSERT INTO users (id) VALUES (?)', ['user-1']), tenantB.first('user-9', 'SELECT * FROM users WHERE id = ?', ['user-9'])]);
Creates a client: the router API bound to a configuration of its own.
A client behaves as if it ran in a separate process. It shares no mapper, mapping cache, placement manifest or epoch, shard size cache, schema record, migration cache or phase observer with the module-level API, a scoped
collegedb(config, callback)or any other client, even when they are given the same providers. Every method works the same as the function of the same name, andcached,invalidateandreconcileAllocationsuse the client's KV store, placement cache and coordinator.Nothing about a client needs
AsyncLocalStorage: state travels with the object, so it is the isolation-safe choice on runtimes without an async context, and the one to use when several configurations serve requests in one isolate. The sync part of the configuration is applied before it returns, like initialize. CallinitializeAsyncon the client to wait for the background checks.