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 🙏

© 2024 – Pkg Stats / Ryan Hefner

psql-wrapper

v0.0.6

Published

Simple wrapper around the psql command line utility (postgres)

Downloads

6

Readme

psql-wrapper

Description

Simple wrapper around the psql command line utility using node's execSync.

Useful to make your own script runner or if you need to make a simple query to a postgres database without the complexity of the pg module (the result of the query can be saved to a .cvs file, for instance).

Install

npm install --save psql-wrapper

Example


// the module exports a function
var Psql = require('psql-wrapper.js');

// options that won't change can be set once with "configure"
Psql.configure({
    "dbname": "my_db"
});

// to execute psql (via child_process' "execSync"), call the exported function;
// any option that was previously set in "configure" will be overriden
var output = Psql({
    "command": "select c1,c2,c3 from some_table"
});
console.log(output);

// we can also save the results to a csv file using the right combination of
// options from psql
var out = Psql({
    "command": "select c1,c2,c3 from some_table",
    "output": "data.csv",
    "no-align": true,
    "tuples-only": true
});

Options for psql

Both Psql (the exported function) and Psql.configure accept an object with options to be given to the psql command line.

The object's keys should be the names of the options accepted by psql (in long format). To see them use psql --help.

The object's values are the arguments for the respective options. If the option doesn't allow an argument, the value true should be used instead.

If the value is falsy (such as an empty string), that option won't be used at all.

This module will only construct the string to be used with execSync (the shell command). It won't make any kind of validation or check to make sure the options are valid. However the psql command line is robust about these kinf of issues, so if an invalid option is given it will abort and the error message is explicit about the problem.

Extra options

The following extra options are available:

  • checkStderr: verify if stderr contains the substring 'ERROR:' and throw an error if so. This is useful to abort the execution of a script runner when some script has SQL syntax errors. Default: true.

  • psqlPath: the path to the psql command line utility. Might be necessary if you have several versions of postgres available. Default: psql.

  • displayShellCommand: display the command to be passed to execSync. Default: true.