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

squirrelify

v0.11.0

Published

PostgreSQL framework for bootstrapping your database, api, and client

Downloads

37

Readme

Squirrel MQ

Squirrel MQ is a lightweight, zero-dependency, and type-safe SQL builder for TypeScript.

Installation

npm install squirrel-mq

Complete Documentation

Usage

Step 1: Define the Schema

// schema.ts
import {AUTO_ID, INTEGER, SERIAL, TEXT, TIMESTAMP, VARCHAR} from 'squirrel-mq/schema/fields';
import { SchemaType } from 'squirrel-mq/schema';

const tableDefaults = {
  created_at: TIMESTAMP({
    default: 'CURRENT_TIMESTAMP',
    withTimezone: true,
    nullable: false,
  }),
  updated_at: TIMESTAMP({
    default: 'CURRENT_TIMESTAMP',
    withTimezone: true,
    nullable: false,
  })
}

export const schema = {
  users: {
    id: PK_AUTO_UUID(),
    name: VARCHAR(255, {nullable: false}),
    email: VARCHAR(255),
    age: INTEGER(),
    ...tableDefaults
  },
  posts: {
    id: PK_AUTO_UUID(),
    title: VARCHAR(255),
    content: TEXT(),
    user_id: UUID({
      references: 'users(id)',
    }),
    ...tableDefaults
  }
}

export type Schema = SchemaType<typeof schema>

Step 2: Deploy the Schema

// schema.deploy.ts
import {schema} from "squirrel-mq/schema";
import { deploySchema } from "squirrel-mq/schema/cicd/deployer";

(async () => {
  const changeSet = await deploySchema(schema);
  console.log(changeSet);
})();

Step 3: Create an API

// api.ts
import { schema, type Schema } from "squirrel-mq/schema";
import { createApi, handler as $ } from "squirrel-mq/api";

const api = createApi(
  schema,
  ({client}) => ({
    'example-users': {
      get: $<Schema['users'][]>(async (req, res) => {
        const users = await client.query('SELECT * FROM users WHERE email ilike $1', [`%example.com%`]);
        res.status(200).json(users.rows);
      }),
      post: $<Schema['users'], Schema['users']>(async (req, res) => {
        const user = await client.query('select * from users where id = 2');
        res.status(200).json(user.rows[0]);
      })
    }
  }),
  {
    caseConversion: {
      in: 'snake',
      out: 'camel',
    },
    pagination: {
      defaultPage: 1,
      defaultLimit: 10,
    }
  }
);

api.auth(client => async (req, res, next) => {
  const unauthorized = () => <const>[401, () => ({error: 'Unauthorized'})];
  const isOp = api.createOpChecker(req);
  const token = req.headers['authorization'];
  const {path} = api.describeRequest(req)
  // Do not use a users email as your auth token, just an example
  const user: Schema['users'] = await client.query('select * from users where email = $1', [token]).then(({rows}) => rows[0]);
  if (!user) return unauthorized(); 
  if (isOp('users/:id', 'GET')) {
    if (user.id.toString() !== path.split('/').pop())
      return unauthorized();
  }
});

export default api;

Step 4: Start the API

// serve.ts
import api from 'squirrel-mq/api';

api.start().then((err) => {
  if (err) {
    console.error(err);
  }
  else {
    console.log(`API is running on port ${api.config.port}`);
  }
});

Step 5: Create a Client

// client.ts
import { createClient } from "squirrel-mq/client";
import api from "squirrel-mq/api";

const client = createClient(api, {
  baseUrl: 'http://localhost:3000/',
  headers: {
    'Authorization': 'Bearer 1234567890',
  }
});

client.models.posts.get(1).then(r => console.log(r));

client.custom('/example-users').post({
  age: 20,
  name: 'John Doe',
  email: '[email protected]',
  id: 1,
  created_at: new Date().toISOString(),
  updated_at: new Date().toISOString(),
}).then(r => console.log(r));