@askdb/mysql
v0.1.0-beta.17
Published
AskDB MySQL integration: introspection connector via information_schema and a mysql2-backed catalog query runner. Pairs with @askdb/core's MYSQL_DIALECT.
Maintainers
Readme
@askdb/mysql
MySQL / MariaDB integration for AskDB. Bundles three pieces:
- Dialect — re-exports
MYSQL_DIALECTandMARIADB_DIALECTfrom@askdb/core. Passdialect: MYSQL_DIALECT(orMARIADB_DIALECT) toask()to target MySQL or MariaDB. - Connector —
createMysqlConnector()implements theConnectorcontract from@askdb/introspectfor live introspection mode. - Catalog runner —
createMysqlCatalogQueryRunner(connectionString)returns an introspection-onlyCatalogQueryRunnerbacked bymysql2(peer dependency, lazy-loaded).
Install
pnpm add @askdb/core @askdb/introspect @askdb/mysqlmysql2 is an optional peer dependency — install it only when using live introspection mode:
pnpm add mysql2For one-off CLI introspection, include the driver in the same ephemeral command:
pnpm dlx -p askdb -p mysql2 askdb introspect --engine mysql --url "$MYSQL_URL"
npx -p askdb -p mysql2 askdb introspect --engine mysql --url "$MYSQL_URL"Usage
NL→SQL
import { ask, loadSchema } from "@askdb/core";
import { MYSQL_DIALECT } from "@askdb/mysql";
const schema = loadSchema("./my-app.schema");
const { sql } = await ask({
question: "How many paid orders were created last month?",
schema,
model,
dialect: MYSQL_DIALECT,
});Use MARIADB_DIALECT instead when your runtime engine is MariaDB.
Introspection
import { introspect } from "@askdb/introspect";
import { createMysqlConnector, createMysqlCatalogQueryRunner } from "@askdb/mysql";
const result = await introspect(
{ mode: "live", runner: createMysqlCatalogQueryRunner(process.env.DATABASE_URL!) },
{ outDir: "./my-app.schema", schemaId: "my-app" },
{ connector: createMysqlConnector() },
);Captured metadata
Tables, views, columns (MySQL-native type strings), primary keys, unique constraints, foreign keys (with referential actions), and indexes.
License
Apache-2.0 © Yahya Gilany. See LICENSE and NOTICE.
