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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dortdb/lang-sql

v1.0.0

Published

SQL parser and executor for DortDB

Readme

DortDB - SQL

This package is a language plugin for DortDB. It adds support for SQL SELECT queries.

Data adapter

The default data adapter implementation allows queries against iterables of JS objects.

const t1 = [
  { a: 1, b: 2, c: 3 },
  { a: 4, b: 5, c: 6 },
];
db.registerSource(['t1'], t1);
db.query('SELECT a, b FROM t1');

Dialect

The package is based on the PostgreSQL dialect. For convenience, identifiers are case-sensitive. Only SELECT queries are supported.

Notable features

PostgreSQL includes several features that are not usual in other SQL flavors. Among them belong the following:

Lateral joins

Lateral joins allow joining of correlated subqueries. In other words, it is possible for the joined subquery to refer to previous tables, and thus to be re-evaluated for different outer contexts.

SELECT t1.attr1, s.attr2 FROM t1
JOIN LATERAL (
SELECT t2.attr2 FROM t2
-- the WHERE clause refers to the outer context
-- the subquery is reevaluated for each t1 row
WHERE t2.attr3 + t1.attr4 > t1.attr5
) AS s

DISTINCT ON

The DISTINCT modifier filters out duplicate values. PostgreSQL allows customizing this behavior.

SELECT DISTINCT ON (attr1, attr2 % 10) attr1, attr2, attr3
FROM t1

Complex aggregate calls

The arguments of aggregate calls such as count or sum may be filtered or sorted.

SELECT
count(DISTINCT attr1) AS distinct_count,
count(attr1) FILTER (WHERE attr1 % 2 = 0) AS even_count,
collect(attr1 ORDER BY attr1) AS ordered_array
FROM t1

Limitations

Currently, some SQL features are not supported, including:

  • window functions
  • common table expressions (CTEs)
  • special GROUP BY behavior (ROLLUP, CUBE, GROUPING SETS)
  • any schema-dependent features (read further)

Schema of data sources

DortDB is by design schema-less. This clashes with some SQL expressions, that only make sense in a schema-based context. Consider the following:

-- which tables are a, b, or c from?
SELECT a, b, c
-- what columns are used in the natural join?
FROM t1 NATURAL JOIN t2

The allowed queries therefore face some restrictions.

  • It must be clear from which tables specific columns originate.
  • Non-qualified column names are only allowed when there is only a single, non-joined data source.
  • Natural joins are disabled.
  • All FROM clause subqueries must have an alias.
  • Selecting all attributes using asterisk * is currently also disabled, although in theory it should be possible.

When an attribute should not be interpreted as belonging to the current table, it should be prefixed by the nonlocal schema. This is relevant when inserting SQL subqueries into languages that do not prefix identifiers, such as Cypher.

-- t1.attr1
SELECT attr1 FROM t1
-- t2.attr2, t2.attr3, attr1 from elsewhere
WHERE (SELECT attr2 FROM t1 WHERE attr3 < nonlocal.attr1)