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

fastify-easy-pg

v0.0.10

Published

Fastify plugin wrapper around easy-psql

Readme

fastify-easy-pg

A Fastify plugin for simplified PostgreSQL model access using easy-psql. It automaticaly scans your PostgreSQL tables per schema and registers their models as classes in memory. Please see how the underlying model functions work, by visiting the docs of easy-psql.

Features

  • Easy integration with PostgreSQL using a model-based approach
  • Optional relation definitions
  • Full access to raw SQL, DB manager, and registered models
  • Hot-reload models without restarting the server

Installation

npm install fastify-easy-pg

Usage

import Fastify from "fastify";
import { fastifyEasyPG } from "@fastify/easy-pg";

const app = Fastify();
const bootstrap = async () => {
  await app.register(fastifyEasyPG, {
    host: "localhost",
    port: 5432,
    database: "postgres",
    user: "postgres",
    password: "postgres",
    relations: [
      {
        alias: "author",
        from_schema: "public",
        to_schema: "public",
        from_table: "posts",
        from_column: "author_id",
        to_table: "users",
        to_column: "id",
        type: "object", // or array ,
      },
    ],
  });

  app.get("/users", async (req, reply) => {
    const model = app.easyPG.model({ table: "users", schema: "public" });
    const users = await model.find({});
    reply.send(users);
  });

  app.listen({ port: 3000 });
};

bootstrap();

Plugin Options

interface FastifyEasyPGPluginOptions {
  host?: string;
  port?: number | string;
  min_pool_size?: number;
  max_pool_size?: number;
  database?: string;
  user?: string;
  password?: string;
  relations?: RelationConfig[];
  logSQL?: boolean; // it only logs when model functions (find,findOne,create,createMany,createTX,createManyTX,update,delete are called)
}

Example with relations

relations: [
  {
    alias: "comments",
    from_schema: "public",
    from_table: "posts",
    from_column: "id",
    to_table: "comments",
    to_column: "post_id",
    type: "array",
  },
];

const model = app.easyPG.model({ table: "posts" });
await model.find({ include: { comments: true } }); // use the alias

Accessing easyPG Utilities

Once registered, fastify.easyPG provides:

  • model({ table, schema?, connection? }): Get a model instance
  • db: Access the underlying DB class from easy-psql
  • dbManager: Access the DB manager
  • rawSQLPart(cb): Create reusable raw SQL parts for more flexibility
  • reloadModels(): Reload the models (useful in development)
  • pool: The node-pg pool