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

@routier/sql-plugin-core

v0.3.0

Published

Shared SQL dialect and result-translation building blocks for routier SQL plugins. Keeps engine-specific knowledge out of @routier/core.

Readme

@routier/sql-plugin-core

Shared SQL generation for Routier's SQL plugins. The SQLite, PostgreSQL, and MySQL plugins all build their statements here.

This package is a building block for plugin authors. Use it if you are writing a plugin for another SQL engine. Application code does not import it.

import {
  getDialect,
  toSql,
  buildGroupedUpdateOperations,
  toColumnValueMap,
  decodeJsonColumns,
} from "@routier/sql-plugin-core";

What it provides

| Export | Purpose | |---|---| | getDialect(name) | Quoting, placeholders, JSON and date encoding, LIKE vs GLOB | | toSql(expression, dialect) | A WHERE fragment and its parameters, from an expression tree | | toColumnAssignments, toColumnValueMap | A partial entity to columns, with renames applied and nested values encoded | | sqlColumnProperties(schema) | Root properties only — the table's real column list | | decodeJsonColumns(rows, schema) | The read-side inverse of the JSON encoding | | buildGroupedUpdateOperations | UPDATE statements for a batch, grouped by changed columns | | buildConditionalUpdateOperations | One token-checked UPDATE per row, for optimistic concurrency |

Contracts

Dialects

sqlite, postgresql, mysql, and mssql. A dialect supplies identifier quoting, the placeholder form, the JSON column type, and the two value encoders — encodeJson and encodeDate.

encodeDate exists because MySQL's DATETIME rejects ISO-8601. The other dialects pass the value through.

Nested values

A nested object or array is one column, named for its root property. schema.properties is flat and lists nested, nested.inner, and nested.inner.value side by side, so building columns from every property produces bogus columns that collide the moment two nested objects share a child name. Use sqlColumnProperties.

Encoding is decided on the value's runtime shape, not its declared type. A property that carries its own .serialize() arrives already stringified, and encoding it again would double-encode.

Update statements

Single-key schemas get one grouped statement per changed-column set:

UPDATE "t" SET "col" = CASE "id" WHEN ? THEN ? … ELSE "col" END WHERE "id" IN (…)

Composite-key schemas get one statement per row, with every identity column in the WHERE. A CASE over one component of a composite key applies one row's value to every row that shares that component.

Statements are never joined with ;. PostgreSQL's extended query protocol and mysql2's default configuration both allow exactly one command per parameterized statement.

Every operation carries keyTuples — each row's full identity. Engines without RETURNING must select rows back with it, not with a bare id.

Placeholders

Each returned statement numbers its own placeholders from the dialect's first. A shared counter across statements is what made them inseparable before.

Testing a new dialect

e2e/src/dialectConformance.ts is a matrix of behaviour every engine must agree on: both operand orders for every comparator, null tests on either side, composite keys, renamed columns, nested JSON, and mixed update batches. Wire a new backend into it and run it against a real server.

String assertions are not enough on their own. The two worst defects this package has had — a reversed null test rendering ? IS NULL, and an operand-order sentinel collision — both produced valid SQL that an engine ran happily and answered wrongly.

Supported versions

Node 18 or later. No runtime dependencies outside @routier/core.