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

qspg

v1.0.10

Published

Manage your schema, connection & migration with simple SQL scripts.

Downloads

38

Readme

QSPG: Quick Scripts Postgres

Manage your schema, connection & migration with simple SQL scripts.

Usage

  1. npm install qspg
  2. Put SQL scripts into directory (e.g. migrations)
  3. Run npm run qspg update ./migrations. Your database is updated!

The scripts are run in alphanumeric order. Scripts are never run more than once (even if you rerun qspg update).

Why?

For most databases, migrations can be done with serially executed migration scripts. This library enables you to quickly write a schema, and keep your database up to date without learning any custom migration tools/libraries.

Simply create a folder called "migrations" and fill with SQL scripts in alphanumeric order of execution, e.g. v01.sql, v02.sql... Then execute npx qspg update ./migrations update your database to the latest version of your schema.

Every time you want to adjust your schema, just add a new script and run qspg update ./migrations and your database will be up to date!

How does it work?

QSPG creates a table public.qspg_metakeystore with a db_version key. Every time a sql script is added to your migrations directory, QSPG notes the version number of the database, and adjusts the db_version such that each script is run exactly once and in order.

Connecting to the database

QSPG can also help you connect to the database via KnexJS. Every time you connect via QSPG, it will run any new migration scripts on the database to ensure the database is up to date.

import qspg from "qspg"
import path from "path"

const conn = qspg({
  migrationsDir: path.resolve(__dirname, "./migrations"),

  // Optional: If set to true, QSPG will create a database with a randomized name, this is
  // great for unit tests. Defaults to true only if USE_TEST_DB env var is set.
  testMode: false,

  // Optional: If seed is true and the seedDir is specified, qspg will seed the
  // database when it's created. This is best used in conjunction with testMode.
  seedDir: path.resolve(__dirname, "./seed"),
  seed: false
}).then(async conn => {
  // Logs a table "users"
  console.log(await conn("users").select("*"))
})

Database Connection

You should have the following environment variables set so QSPG can connect to your database.

| Environment Variable | Default | | -------------------- | --------- | | POSTGRES_HOST | localhost | | POSTGRES_PORT | 5432 | | POSTGRES_USER | postgres | | POSTGRES_PASS | | | POSTGRES_DB | postgres |

Commands

| Command | Description | | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- | | qspg update $MIGRATIONS_DIR | Update the database using the scripts within $MIGRATIONS_DIR. Updates the db_version appropriately. | | qspg compile $MIGRATIONS_DIR migrate.sql | Compile the scripts within $MIGRATIONS_DIR to generate a migrate.sql that, when executed, runs each script and updates the db_version. | | qspg init package | Creates a bootstrap project for QSPG where your database is an NPM module. |