npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@askdb/client

v1.0.0-beta.5

Published

Config-aware AskDB facade: resolves schema, model, and dialect from config so callers only pass a question.

Readme

@askdb/client

Config-aware AskDB facade. Resolves schema, model, and dialect from your runtime config so callers only pass a question.

Quick start

import { bootstrapAskDbEnv, getAskDbRuntimeConfig } from "@askdb/config";
import { openaiProvider } from "@askdb/ai-openai";
import { createAskDb } from "@askdb/client";

// bootstrapAskDbEnv() reads .env and askdb.config.* into an in-memory snapshot.
// getAskDbRuntimeConfig() then returns a typed view over that snapshot.
// Both calls are needed: bootstrap populates the store; getAskDbRuntimeConfig reads it.
bootstrapAskDbEnv();
const askdb = createAskDb({
  config: getAskDbRuntimeConfig(),
  providers: [openaiProvider], // the client builds its AI registry from these adapters
});

const { sql } = await askdb.ask("top 10 customers by revenue");

Pass the adapter(s) for whichever ai.provider your config selects. Advanced alternative: build a registry yourself with createAiRegistry from @askdb/ai and pass it as registry instead (e.g. to share one registry across several clients) — exactly one of providers or registry is required.

Per-call overrides

All three resolution axes accept optional per-call overrides:

| Override | Type | Default | |---|---|---| | schema | { path } | { json } | { schema } | NormalizedSchema | From createAskDb({ schema }) → config host.schemaPath/host.schemaJson → env | | model | AskDbLanguageModel | From registry via config ai.aiEnv | | dialect | AskDialectInput | Config dialect → schema provider"postgres" |

const { sql } = await askdb.ask("count active users", {
  dialect: "mysql",
  schema: { path: "./schemas/prod.schema" },
});

Parameterized output

askdb.ask() returns the same AskPipelineResult as @askdb/core's ask(), including optional unboundSql, params, parameters, and preparedQuery when the model complies (default parameterize: true). The facade forwards options and returns the core result verbatim — no client-side binding logic.

import { bindPreparedQuery } from "@askdb/core";

const result = await askdb.ask("How many cities does Colorado have?", { tenantScope });

await pool.query(result.sql);
await pool.query(result.unboundSql!, result.params);

const rebound = bindPreparedQuery(result.preparedQuery!, {
  state_name: "Utah",
  ":tenant_agency_ids": authorizedAgencyIds,
});
await pool.query(rebound.sql);

Every ask() is still one model call. Set { parameterize: false } to opt out of the extra output tokens. bindPreparedQuery does not authorize tenant IDs — that remains the host's job when building tenantScope. Prefer params over tenantParams when using the new fields.

Multi-tenant usage

The schema and model caches are per-client-instance. For multi-tenant servers where each tenant has a different schema, either:

  • Create one AskDbClient per tenant, or
  • Pass per-call schema and/or model overrides (bypasses the cache).

reload()

Drops the cached schema and model so the next ask() re-resolves them from config:

askdb.reload();

onResolve hook

Inspect how schema, model, and dialect resolved on each call — useful for logging or debugging:

const askdb = createAskDb({
  config,
  providers: [openaiProvider],
  onResolve: ({ dialect, modelSource }) => {
    console.log(`dialect=${dialect.dialect} (${dialect.source}), model=${modelSource}`);
  },
});