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

@yamf/services-postgres

v0.1.2

Published

Postgres.js wrapper for YAMF: parameterized SQL templates, camelCase result mapping, and safe placeholder validation.

Readme

@yamf/services-postgres

Postgres.js wrapper for YAMF: parameterized SQL templates, camelCase result mapping, and safe placeholder validation.

Node License

Installation

npm install @yamf/services-postgres

Peer dependencies: @yamf/core, @yamf/shared. The package uses postgres (postgres npm package).

Quick Start

import { registryServer, createService, callService } from '@yamf/core'
import createPostgreSqlService from '@yamf/services-postgres'

await registryServer()

const postgres = await createPostgreSqlService({
  serviceName: 'postgres-service',
  psqlConfig: 'postgres://user:pass@localhost/dbname'
  // or: { PGDATABASE: 'yamf', PGUSER: 'yamf', PGPASSWORD: 'changeme' }
})

// Call from another service or gateway
const [row] = await callService('postgres-service', {
  template: `SELECT user_id, username, is_active FROM yamf.user WHERE username = :username`,
  data: { username: '[email protected]' }
})
// row has camelCase keys: userId, username, isActive

Features

  • Parameterized queries – Template placeholders :name are replaced with safe parameters; no string interpolation of user input.
  • CamelCase mapping – Result rows are converted from snake_case to camelCase by default (via @yamf/shared).
  • Placeholder validation – Only valid identifiers are allowed for placeholder names to prevent injection.
  • Postgres.js – Uses postgres under the hood.

API

createPostgreSqlService(options)

| Option | Default | Description | |---------------|---------------------|-------------| | serviceName | 'postgres-service' | YAMF service name to register. | | psqlConfig | env / { PGDATABASE, PGUSER, PGPASSWORD } | Postgres connection string or config object. | | schema | null | Optional schema setup. | | seed | null | Optional seed logic. |

Payload

Call the service with:

  • template (string) – SQL with :placeholder names in camelCase (e.g. :userId, :isActive).
  • data (object) – Keys match placeholder names (camelCase). All placeholders must have a value.
  • options (optional) – e.g. { mapCase: true } (default). Set mapCase: false to skip camelCase conversion.

Returns the result of the query (array of rows, or raw result from postgres.js). With mapCase: true, row keys are camelCase.

Template and data

  • Use camelCase for placeholder names in the template and for keys in data: :userId, :username, :isActive.
  • Write snake_case in SQL as usual: user_id, username, is_active.
  • Only valid identifier names are allowed for placeholders (alphanumeric and underscore, no SQL injection via placeholder names).

Example:

await callService('postgres-service', {
  template: `
    SELECT user_id, username, is_registered, is_active
    FROM yamf.user
    WHERE user_id = :userId OR username = :username
  `,
  data: { userId: 1, username: '[email protected]' }
})

Using with other services

This service is the data layer for @yamf/services-user and for custom auth (e.g. looking up users and verifying passwords). For a full example that wires Postgres + User + Auth together, see the psql-user-auth example in the repo.

Dependencies

  • postgres – Postgres.js driver
  • @yamf/core – createService, callService, HttpError
  • @yamf/shared – toCamelCase for result mapping

License

MIT