@askdb/postgres
v0.2.0-beta.18
Published
AskDB Postgres integration: re-exports the Postgres DialectSpec from @askdb/core and ships the introspection connector (live + from-export bundle), catalog SQL templates, and a `pg`-backed catalog query runner.
Maintainers
Readme
@askdb/postgres
PostgreSQL integration for AskDB. Bundles four pieces:
- Dialect —
postgresDialectplusvalidatePostgresSelectSqlandgeneratePostgresSelectSql. Passdialect: postgresDialectto@askdb/core'sask()to make the pipeline target PostgreSQL. - Connector —
createPostgresConnector()implements theConnectorcontract from@askdb/introspectfor both live andfrom-export(air-gapped bundle) modes. - Templates — the catalog SQL suite that drives both modes is exported as
POSTGRES_TEMPLATE_BUNDLE. - Catalog runner —
createPostgresCatalogQueryRunner(connectionString)returns an introspection-onlyCatalogQueryRunnerbacked bypg(peer dependency, lazy-loaded).
Install
pnpm add @askdb/core @askdb/introspect @askdb/postgres pgpg is an optional peer dependency. Install it only if you plan to use live introspection mode. The CLI does not bundle pg; install it in your project or include it in the same one-off command:
pnpm dlx -p askdb -p pg askdb introspect --engine postgres --url "$DATABASE_URL"
npx -p askdb -p pg askdb introspect --engine postgres --url "$DATABASE_URL"Usage
import { ask, loadSchema } from "@askdb/core";
import { postgresDialect } from "@askdb/postgres";
const schema = loadSchema("./fixtures/schemas/orders-users.schema");
const out = await ask({
question: "How many orders did each user place last month?",
schema,
model: /* a LanguageModel */,
dialect: postgresDialect,
});Introspection
import { introspect } from "@askdb/introspect";
import { createPostgresCatalogQueryRunner, createPostgresConnector } from "@askdb/postgres";
const result = await introspect(
{ mode: "live", runner: createPostgresCatalogQueryRunner(process.env.DATABASE_URL!) },
{ outDir: "./schemas/orders-users.schema", schemaId: "orders-users" },
{ connector: createPostgresConnector() },
);The connector input shape (PostgresIntrospectionInput) lives in this package — @askdb/introspect is engine-agnostic and does not know about live vs. from-export modes.
License
Apache-2.0 © Yahya Gilany. See LICENSE and NOTICE.
