Architecture
One core, drivers for database types, hosted providers that reuse a driver. Shared lifecycle, native queries, one catalog shape.
docs/architecture.mdStatus: intended design. Public types and connect() live in core. Driver and hosted provider packages are not implemented yet. The shape is one core, drivers for database types, and hosted providers that reuse a driver.
db-sdk core types, connect(), safety helpers
@db-sdk/postgres Postgres driver (first)
@db-sdk/firestore Firestore driver (first)
@db-sdk/supabase hosted provider → Postgres driver
@db-sdk/<name> later drivers or hosted providersProvider contract
connect({ provider }) opens a handle to an existing database; it does not create one. Each provider has an id (what you stored) and a driver (the query family).
interface DatabaseProvider<TQuery = unknown> {
readonly id: string;
readonly driver: string;
readonly capability: "relational" | "document";
test(signal?: AbortSignal): Promise<void>;
introspect(signal?: AbortSignal): Promise<Catalog>;
query(input: TQuery, signal?: AbortSignal): Promise<QueryResult>;
close(): Promise<void>;
}Catalog and results
Introspection returns one catalog shape so UIs and models share a picture of the store. Relational drivers fill it from information_schema. Document drivers sample documents and union keys. Caching is a host concern.
Capabilities group tools for hosts. They do not flatten drivers into one AST. A later MongoDB driver should use Mongo's read API, not Firestore's filter list.
Adding a driver or hosted provider
- Drivers implement test, introspect, query, and close for a database type.
- Hosted providers own product OAuth/API, then open an existing driver.
- Map native types into catalog field strings.
- Enforce that driver's read-only policy in query.
- Export a factory; set id and driver (often the same for raw drivers).
Keep going
Guide
Core idea
Connect, describe, and read a database whose schema you don't control at compile time — without turning every driver into SQL.
Pattern
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.
Reference
Postgres
First SQL driver: connection, introspection from information_schema, parameterized SELECT, limits and timeouts.