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

sqlscope-rs

v0.7.0

Published

Scope-aware SQL analysis and rewriting: row filters, CTE injection, table rewrites, column lineage.

Readme

sqlscope-rs

Scope-aware SQL analysis and rewriting for TypeScript and JavaScript: row filters, CTE injection, table rewrites and column lineage over 30+ SQL dialects. It runs sqlscope (Rust, built on the polyglot SQL engine) as a WebAssembly module bundled in the package: no native library, no install scripts.

npm install sqlscope-rs

| Function | Purpose | | --- | --- | | applyRowFilter | Filter every in-scope table by a predicate (row-level security). | | injectCtes | Prepend CTE definitions to a query's root WITH. | | rewriteTables | Replace table references with other tables or derived tables. | | columnOrigins | Source columns whose values reach the result (column lineage). | | outputColumns | Names of the columns a statement outputs. | | referencedColumns | Columns referenced anywhere (filters included), per table. | | columnUsages | Column references together with the clause they appear in. |

Usage

import { applyRowFilter, columnOrigins, columnUsages, injectCtes, rewriteTables } from "sqlscope-rs";

applyRowFilter("SELECT id FROM orders", "tenant_id = 7", { dialect: "postgres" });
// 'SELECT id FROM (SELECT * FROM orders WHERE tenant_id = 7) AS orders'

applyRowFilter("SELECT * FROM a JOIN b ON a.id = b.id", "tenant_id = 7", { tableNames: ["a"] });

columnOrigins(
  "SELECT o.id, p.amount FROM orders o JOIN payments p ON o.id = p.order_id WHERE o.status = 'PAID'",
);
// { orders: ['id'], payments: ['amount'] }

columnOrigins("SELECT * FROM orders", { schema: { orders: ["id", "status"] } });
// { orders: ['id', 'status'] }

columnUsages("SELECT id FROM orders WHERE status = 'PAID'");
// [{ table: 'orders', column: 'id', clause: 'SELECT' },
//  { table: 'orders', column: 'status', clause: 'WHERE' }]

injectCtes("SELECT * FROM foo", [{ name: "foo", query: "SELECT id FROM t" }]);
// 'WITH foo AS (SELECT id FROM t) SELECT * FROM foo'

rewriteTables("SELECT col1 FROM myschema.mytable", [
  { matchKey: "myschema.mytable", inline: { table: "view1", schema: "vsch" } },
]);
// 'SELECT col1 FROM (SELECT * FROM vsch.view1) AS mytable'

Every function is synchronous. Options:

| Option | Read by | | --- | --- | | dialect | all (default "trino"; "postgres", "mysql", "spark", "snowflake", "bigquery", ...) | | schema | columnOrigins, outputColumns, referencedColumns, columnUsages | | tableNames, tablePatterns, defaultDb | applyRowFilter | | stripCatalogs | rewriteTables |

schema maps table names (bare, schema.table or catalog.schema.table) to their ordered columns, as an object or a Map.

Errors are thrown as InvalidArgumentError, ParseError, UnsupportedError or InternalError, all subclasses of SqlscopeError.

The sqlscope README describes each operation in detail.

Runtimes

Node.js (≥ 20.19), Deno and Bun load the WebAssembly module when the package is imported (import or require); just call the functions.

Browsers, workers and edge runtimes load it asynchronously: await init() once before calling anything else.

import { init, outputColumns } from "sqlscope-rs";

await init(); // fetches sqlscope.wasm next to the package
outputColumns("SELECT a, b FROM t");

init() resolves sqlscope.wasm with new URL(..., import.meta.url), which webpack, Rollup and esbuild handle. With Vite, import the module's URL explicitly:

import { init } from "sqlscope-rs";
import wasmUrl from "sqlscope-rs/sqlscope.wasm?url";

await init(wasmUrl);

init also accepts a Response, the bytes, or a compiled WebAssembly.Module; initSync(bytes) loads synchronously. Calling init() under Node.js is harmless, so the same code runs everywhere.

The module is about 9 MB (2.5 MB gzipped). V8 compiles it lazily; under sustained load its optimizing compiler can hold several hundred MB of optimized code. Run Node.js with --liftoff-only to trade speed for memory.

License

MIT