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

    Function toProvider

    • Detects the right CollegeDB shard provider for an arbitrary binding.

      This removes the per-app "is this a D1 binding, a Drizzle client, or a raw SQLite client?" wiring that every consumer otherwise rewrites. Resolution order:

      1. A raw Drizzle client (run/all/get/execute) is wrapped with createDrizzleSQLProvider when options.sql is supplied.
      2. A value already implementing the SQLDatabase contract (a D1 binding, or a provider from any create*Provider) is returned as-is.
      3. A client exposing prepare(sql) is wrapped with createSQLiteProvider.
      4. Anything else returns null (unrecognized).

      Parameters

      • binding: unknown

        Candidate database binding

      • options: ToProviderOptions = {}

        Resolution options (Drizzle sql tag)

      Returns SQLDatabase | null

      A shard provider, or null when the binding is not recognized

      1.2.4

      import { sql } from 'drizzle-orm';
      const provider = toProvider(env.DB_EAST, { sql });
      if (!provider) throw new Error('Unrecognized database binding');