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

@dbsp/nql

v1.9.4

Published

NQL (Natural Query Language) - A human and LLM-friendly query language for databases

Readme

@dbsp/nql

npm version license

NQL (Natural Query Language) — a human- and LLM-friendly pipe-based query language that compiles to IntentAST for @dbsp/core.

Installation

pnpm add @dbsp/nql

Quick Start

// doctest: skip — exec-only operation; compile from @dbsp/nql is not in doctest preamble and orm.from(intent).all() requires a real PostgreSQL connection
import { createPgsqlCompileOnlyAdapter } from '@dbsp/adapter-pgsql';
import { compile } from '@dbsp/nql';

// Compile an NQL query to a public intent bundle
const compiled = compile(
  "users | where active = true | select name, email | order name asc | limit 20",
  db.model
);

if (!compiled.success || !compiled.ast?.query) {
  throw new Error(compiled.errors.map((e) => e.message).join(', '));
}

// Pass the whole bundle to the adapter; bound params are explicit public IR nodes
const adapter = createPgsqlCompileOnlyAdapter();
const query = adapter.compile(compiled.ast, { model: db.model });

Syntax overview

-- Basic selection with filter
users | where status = 'active'

-- Computed columns and ordering
orders | select id, total, tax | order total desc | limit 10

-- Relations (auto-resolved from schema refs)
posts | include author | where published = true

-- CTEs (WITH clause)
with recent AS (orders | where createdAt > '2024-01-01')
recent | select id, total

-- Aggregation
orders | group customerId | select customerId, sum(total) as revenue

Key features

  • Pipe syntax — Readable left-to-right data flow (table | filter | select | order)
  • SQL-style literals — Single-quoted strings ('value'), not double-quoted
  • Named parameters — Bind runtime values with :name in expression positions
  • CTE supportWITH name AS (subquery) for named subqueries
  • Mutation support — Insert, update, delete, upsert, and insert/upsert ... from ... pipelines
  • Schema-aware — Validates column names and relation paths against ModelIR at parse time
  • LLM-friendly — Concise syntax designed for AI-generated queries
  • Chevrotain-based — Robust lexer + parser with structured error recovery
  • Composable — Output IntentAST is the same type used by the TypeScript fluent builders

Named parameters

Use :name placeholders for runtime values and pass a params map to the compiler:

// doctest: skip — illustrative direct compiler params example
import { createPgsqlCompileOnlyAdapter } from '@dbsp/adapter-pgsql';
import { compile } from '@dbsp/nql';

const compiled = compile(
  'users | where id = :id and active = :active | limit :limit',
  db.model,
  undefined,
  { params: { id: 42, active: true, limit: 10 } },
);

if (!compiled.success || !compiled.ast?.query) {
  throw new Error(compiled.errors.map((e) => e.message).join(', '));
}

const adapter = createPgsqlCompileOnlyAdapter();
const query = adapter.compile(compiled.ast, { model: db.model });

Missing params fail compilation. null binds SQL NULL; undefined, NaN, and Infinity are rejected. The @dbsp/core orm.nql template tag builds on the same mechanism for ${value} interpolation. See Named Parameters and Template Binding for the full contract.

Tag mutations

The @dbsp/core orm.nql tag can compile and execute final mutation statements. Use .dump() for compile-only inspection; mutation dumps expose parameters instead of query dump params.

const mutationDump = orm.nql<unknown>`
  insert into users set name = ${'Alice'}, email = ${'[email protected]'}
`.dump() as {
  sql: string;
  parameters: readonly unknown[];
};

console.log(mutationDump.sql);
console.log(mutationDump.parameters);

Read-only | bind statements can feed a final insert ... from ... or upsert ... from ... mutation:

const pipelineDump = orm.nql<unknown>`posts
  | where published = ${false}
  | select id, title, authorId, published, createdAt
  | bind draft_posts
insert into posts from draft_posts`
  .dump() as {
  sql: string;
  parameters: readonly unknown[];
};

console.log(pipelineDump.sql);
console.log(pipelineDump.parameters);

Tag mutation execution uses the normal mutation hooks. Multi-statement tags require every non-final statement to end with | bind <name>, and writable mutation bodies inside | bind are rejected by the tag executor.

Documentation

License

MIT