Skip to content

jeswin/pg-params

Repository files navigation

pg-params

pg doesn't support named parameters, to keep things lightweight and simple. However, that makes queries brittle.

pg-params contains helper methods to make parameterized queries easier.

Installation

npm install pg-params

Usage

Here's an example.

import Params from "pg-params";

const params = Params({
  name: "jeswin",
  country: "india"
});

const queryText = `
  SELECT * FROM user WHERE 
  name=${dbParams.id("name")} AND 
  country=${dbParams.id("country")}`;

client.query(queryText, dbParams.values());

About

A wrapper around the excellent node pg library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published