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

sqlslice

v0.1.0

Published

Composable SQL architecture framework for breaking large relational queries, stored procedures, and materialized views into reusable maintainable slices.

Readme

sqlslice

Composable SQL architecture framework for breaking large relational queries, stored procedures, and materialized views into reusable, maintainable slices.

Installation

npm install sqlslice

Concepts

| Term | Description | |---|---| | Slice | A named, reusable SQL unit (query, CTE fragment, view reference, or procedure call). | | SliceRegistry | An in-memory store of registered slices. | | SqlSliceEngine | Ties a DatabaseConnector to a SliceRegistry; runs and composes slices. | | DatabaseConnector | Abstract base class — extend it to add a new database driver. |

Quick start

import {
  PostgresConnector,
  SqlSliceEngine,
  Slice,
} from 'sqlslice';

const connector = new PostgresConnector({
  host: 'localhost',
  port: 5432,
  database: 'mydb',
  user: 'admin',
  password: 'secret',
});

const engine = new SqlSliceEngine(connector);
await engine.connect();

// 1. Define slices
const activeUsers = new Slice({
  name: 'active_users',
  type: 'fragment',
  description: 'Users who logged in within the last 30 days',
  sql: `SELECT id, name, email FROM users WHERE last_login >= NOW() - INTERVAL '30 days'`,
});

const premiumUsers = new Slice({
  name: 'premium_users',
  type: 'fragment',
  sql: `SELECT user_id FROM subscriptions WHERE plan = 'premium' AND status = 'active'`,
});

// 2. Register
engine.register(activeUsers).register(premiumUsers);

// 3. Run a single slice
const { rows } = await engine.run('active_users');

// 4. Compose slices as CTEs + a final SELECT
const result = await engine.compose(
  ['active_users', 'premium_users'],
  `SELECT au.* FROM active_users au
   JOIN premium_users pu ON pu.user_id = au.id`,
);
// Emits:
//   WITH active_users AS (...),
//        premium_users AS (...)
//   SELECT au.* FROM active_users au JOIN premium_users pu ON ...

await engine.disconnect();

Dynamic SQL with template params

Pass a function as sql to build the query at runtime:

const recentOrders = new Slice<{ days: number }>({
  name: 'recent_orders',
  type: 'query',
  sql: ({ days }) =>
    `SELECT * FROM orders WHERE created_at >= NOW() - INTERVAL '${days} days'`,
});

engine.register(recentOrders);

const { rows } = await engine.run('recent_orders', { days: 7 });

Positional bind parameters

Use $1, $2, … placeholders and pass bindParams for safe parameterized queries:

const ordersByStatus = new Slice({
  name: 'orders_by_status',
  type: 'query',
  sql: `SELECT * FROM orders WHERE status = $1`,
});

engine.register(ordersByStatus);

const { rows } = await engine.run(
  'orders_by_status',
  undefined,
  ['shipped'],       // bindParams → $1 = 'shipped'
);

OOP connector hierarchy

DatabaseConnector  (abstract)
└── PostgresConnector

To add a new database, extend DatabaseConnector:

import { DatabaseConnector, QueryResult } from 'sqlslice';

export class MySQLConnector extends DatabaseConnector {
  get databaseType() { return 'mysql'; }
  get isConnected() { /* ... */ }

  async connect() { /* ... */ }
  async disconnect() { /* ... */ }
  async query<T>(sql: string, params?: unknown[]): Promise<QueryResult<T>> { /* ... */ }
  async execute(sql: string, params?: unknown[]): Promise<void> { /* ... */ }
}

Then pass it straight into SqlSliceEngine — no other changes needed.

Slice types

| type | Use for | |---|---| | 'query' | Full SELECT statements | | 'fragment' | Sub-queries / CTE bodies | | 'view' | References to materialized / regular views | | 'procedure' | Stored procedure calls |

API reference

new PostgresConnector(config: PostgresConfig)

| Option | Type | Default | |---|---|---| | host | string | — | | port | number | 5432 | | database | string | — | | user | string | — | | password | string | — | | ssl | boolean \| object | — | | poolSize | number | 10 | | idleTimeoutMillis | number | 30000 | | connectionTimeoutMillis | number | 2000 |

SqlSliceEngine

| Method | Description | |---|---| | .connect() | Open the underlying connection pool. Returns this (chainable). | | .disconnect() | Close the pool. | | .register(slice) | Add a slice to the registry. Returns this (chainable). | | .run(name, templateParams?, bindParams?) | Execute a single slice. | | .compose(names, finalSelect, options?) | Build a WITH … AS (…) query and execute it. | | .getRegistry() | Access the SliceRegistry for introspection. |

License

MIT