@earth-app/collegedb
    Preparing search index...

    Function initializeFromEnv

    • Initializes CollegeDB by discovering shard bindings from a Workers env.

      On Cloudflare, D1 bindings live on env under conventional names (DB_EAST, DB_WEST, ...). This scans env for those, resolves each with toProvider (D1 / Drizzle / SQLite), wires the KV store (raw Workers KV is auto-wrapped via createWorkersKVProvider), and calls initialize. It removes the ~40-line hand-rolled wiring most Worker apps otherwise write.

      Shard names are the binding name lowercased with _ replaced by - (DB_EAST -> db-east).

      Parameters

      • env: Record<string, unknown>

        The Worker environment bindings

      • options: InitializeFromEnvOptions = {}

        KV/coordinator overrides, discovery prefixes, strategy, etc.

      Returns string[]

      The list of shard names that were registered

      If no KV binding or no shard bindings can be resolved

      1.2.4

      import { sql } from 'drizzle-orm';

      export default {
      async fetch(request, env) {
      if (!isInitialized()) {
      initializeFromEnv(env, { sql, strategy: { read: 'location', write: 'hash' } });
      }
      // ... routed queries
      }
      };