Configuration object containing all necessary bindings and settings
// Basic setup with multiple shards - auto-migration happens automatically
initializeAsync({
kv: env.KV,
shards: {
'db-primary': env.DB_PRIMARY, // Existing DB with data
'db-secondary': env.DB_SECONDARY // Another existing DB
},
strategy: 'round-robin'
});
// Existing data is now automatically accessible via CollegeDB!
// Advanced setup with coordinator
initializeAsync({
kv: env.KV,
coordinator: env.ShardCoordinator,
shards: {
'db-east': env.DB_EAST,
'db-west': env.DB_WEST,
'db-central': env.DB_CENTRAL
},
strategy: 'hash'
});
Sets up the global configuration for the CollegeDB system asynchronously. This must be called before any other operations can be performed. The configuration includes KVstorage, available D1 shards, optional coordinator, and allocation strategy.
This will also automatically detect and migrate existing databases without requiring additional setup. If shards contain existing data with primary keys, CollegeDB will automatically create the necessary mappings for seamless operation.
Compared to
initialize
, this method waits for the background check to finish.