Resolve a provider at runtime
Customer connections are a stored provider id plus credentials. A registry should open the handle without a compile-time switch.
Customer connections are not known at compile time. The host stores a provider id plus encrypted credentials, then resolves a provider when a request arrives. A hardcoded switch does not scale.
import { connect, createRegistry } from "@db-sdk/core";
import { postgres } from "@db-sdk/postgres";
import { firestore } from "@db-sdk/firestore";
const registry = createRegistry({ postgres, firestore });
const db = await connect({
provider: registry.resolve(
connection.provider,
connection.credentials,
),
});Intended direction
Factory functions and a registry. The exact API is not decided. The requirement is: a stored provider id plus credentials must be enough to open a connection without a compile-time switch.
Keep going
Pattern
Attach a customer database
Resolve the provider from stored config, prove the credential works, then introspect the schema after they connect.
Guide
Architecture
One core, drivers for database types, hosted providers that reuse a driver. Shared lifecycle, native queries, one catalog shape.
Reference
Postgres
First SQL driver: connection, introspection from information_schema, parameterized SELECT, limits and timeouts.