New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@badrequest400/pg-named-params

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@badrequest400/pg-named-params

Parameterise queries for pg with named variables

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-20%
Maintainers
1
Weekly downloads
 
Created
Source

pg-named-params

Simple query builder function for pg that let's you use named parameters instead of positional arguments to enhance readability.

Installation

npm i @badrequest400/pg-named-params

Usage

import { build } from '@badrequest400/pg-named-params';
// or if not using ES modules
// const { build } = require('@badrequest400/pg-named-params');

const query = build(
  `SELECT * FROM users
    WHERE name = $name
    AND age > $age
    AND status = $status
    AND type = $type
    AND created_at > NOW() - INTERVAL '$daysAgo day'
    AND organisation_id = $organisationId
  `,
  { name: 'John', age: 23, status: 'active', type: 'user', daysAgo: 7, organisationId: 1 }
);

pg.query(query.text, query.values);

Easier on the eyes than the normal pg API:

pg.query(
  `SELECT * FROM users
    WHERE name = $1
    AND age > $2
    AND status = $3
    AND type = $4
    AND created_at > NOW() - INTERVAL '$5 day'
    AND organisation_id = $6
  `,
  [ 'John', 23, 'active', 'user', 7, 1 ]
);

FAQs

Package last updated on 11 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc