# askdb Command-line frontend for [`@askdb/core`](https://www.npmjs.com/package/@askdb/core). Ask natural-language questions and get checked SQL from the configured dialect. Published on npm as [`askdb`](https://www.npmjs.com/package/askdb) (unscoped); the `askdb` binary name is unchanged. > **Status:** pre-1.0. ## Install ```bash pnpm add -g askdb # or run without installing: pnpm dlx askdb --help # e.g. scaffold config: pnpm dlx askdb init ``` The CLI delegates live introspection to AskDB connector packages; each connector owns any database driver it needs. `askdb init` installs `@askdb/config` and the driver for your selected database — only for the path you chose. ## Live introspection drivers For project-local usage, install the CLI plus the driver for the engine you want to introspect: ```sh pnpm add -D askdb pnpm add mssql pnpm exec askdb introspect --engine sqlserver --url "$SQLSERVER_URL" ``` For one-off runs, include the driver in the same ephemeral command: ```sh pnpm dlx -p askdb -p mssql askdb introspect --engine sqlserver --url "$SQLSERVER_URL" npx -p askdb -p mssql askdb introspect --engine sqlserver --url "$SQLSERVER_URL" ``` Use `pg` for Postgres, `mysql2` for MySQL, `better-sqlite3` for SQLite, and `mssql` for SQL Server. ## Quickstart ```bash export OPENAI_API_KEY=sk-... askdb ask \ --schema fixtures/schemas/orders-users.schema \ --question "How many users signed up last week?" ``` AskDB returns SQL for review. Run approved SQL outside AskDB under your own database roles, tenant policy, and audit logging. ## Common flags - `--schema ` — schema directory, bundled JSON, or `schema.json` file. - `--mode ` — one of the supported modes (see `docs/contracts/modes-v1.md`). - `--explain` — emit heuristic guardrail metadata alongside the SQL. - `--log-level ` — Pino log level (silent, error, warn, info, debug, trace). Run `askdb --help` for the full list. ## Init ```bash askdb init # TTY wizard askdb init --yes # non-interactive, Postgres + OpenAI defaults askdb init --yes --database sqlserver # non-interactive, SQL Server askdb init --yes --database sqlite --sqlite-file SQLITE_FILE ``` In a terminal, `askdb init` opens a short wizard: choose your database, AI provider, RAG store, and whether to enable Studio execute. A flag you pass answers its question, and the wizard skips it. It writes only the relevant config branches and installs only the packages for your chosen path (e.g. `mssql` for SQL Server, `better-sqlite3` for SQLite — not all drivers). In CI or scripts, pass `--yes` and use flags instead of prompts. See `askdb init --help` for the full flag list. `askdb.config.ts` is TypeScript-checked and uses `env("VAR_NAME")` for every secret-bearing value — no real keys are written to disk. ## Enrichment UI ```bash askdb studio --schema my-app.schema ``` `askdb studio` starts a local browser UI for browsing tables, editing schema enrichment, requesting AI suggestions, and generating sample NL-to-SQL output before shipping the schema. `askdb enrich` is an alias for the same command. ## Introspection Postgres live and air-gapped introspection: ```bash askdb introspect --url "$DATABASE_URL" --out my-app.schema --schema-id my-app askdb introspect --from-export ./pg-export-bundle --out my-app.schema --schema-id my-app ``` Prisma schema-file introspection does not connect to the database. It needs `@askdb/prisma`, which `askdb` doesn't install: add it to your project (on pnpm 11, `pnpm add --allow-build=@prisma/engines @askdb/prisma`; see [the Prisma guide](https://askdb.tools/guides/integrations/prisma/#install)): ```bash askdb introspect --engine prisma --prisma-schema ./prisma --out my-app.schema askdb introspect --engine prisma --prisma-schema ./prisma/schema.prisma --print askdb introspect --engine prisma --prisma-schema ./prisma --diff my-app.schema ``` ## RAG `askdb rag` chunks and embeds a schema artifact for retrieval and queries the index. It reads `rag.embedder`, `rag.store`, `rag.storeConfig`, and `ai.embedding` from `askdb.config.*`, and its flags override them. It replaces the `askdb-rag` binary that `@askdb/rag` used to ship. ```bash askdb rag index my-app.schema askdb rag query my-app.schema --question "customer signups" -k 8 ``` See the [CLI reference](https://askdb.tools/reference/cli/#askdb-rag) for every flag, including `setup-store` for provisioning a pgvector table. ## Environment The CLI loads `.env` from the current working directory (via dotenv), then evaluates an optional AskDB config file (`askdb.config.*` or `.config/askdb.*`) via [`@askdb/config`](https://www.npmjs.com/package/@askdb/config) (`bootstrapAskDbEnv`), which installs the **runtime snapshot** used by `getAskDbRuntimeConfig()` — AskDB does **not** copy the full flattened map into `process.env`. Run `askdb init` to create **`askdb.config.ts`** with nested `defineConfig` and `env()` examples; optional `.env` guidance is in comments in that file (no `.env` is generated). `askdb init` **skips** loading config so a broken template never blocks scaffolding. In an app directory, it also runs your package manager to add **`@askdb/config`** and the database driver the config connects with, so `askdb.config.ts` imports resolve immediately. At a workspace root, whose `pnpm-workspace.yaml` lists at least one package under `packages` or whose `package.json` has `workspaces`, it prints the command to run in the right package instead. A `pnpm-workspace.yaml` that holds only settings doesn't make a workspace root. Settings come from `askdb.config.ts`; bind any of them to an environment variable of your choosing with `env("NAME")`. The one AskDB variable the CLI reads from the environment is `ASKDB_DEBUG`, which prints the stack trace of an unexpected error. | Config key | Purpose | |---|---| | `ai.providerConfig..apiKey` | The language model provider's key, e.g. `env("OPENAI_API_KEY")`. | | `introspection.outputDir` | Where `askdb introspect` writes the schema artifact, and the default `askdb ask --schema`. Default `./askdb/`. | | `introspection.providerConfig..databaseUrl` | Connection string `askdb introspect` uses when you omit `--url`, e.g. `env("DATABASE_URL")`. | | `dev.mockSql` | Bypass live model calls in tests/dev (or pass `--mock-sql`). | ## License Apache-2.0 © Yahya Gilany. See [LICENSE](./LICENSE) and [NOTICE](./NOTICE).