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

pg-qry-exec

v2.0.18

Published

"Postgre Query Executor"

Downloads

137

Readme

pg-qry-exec

This module provides a simple interface for executing PostgreSQL queries with with or without arguments and provides comprehensive response handling with logging and performance monitoring capabilites for PostgreSQL databases.

Installation

Install from npm :

$ npm install pg-qry-exec

Supported Properties

| Function Name | Description | | ------------- | ----------- | | getRowCount | gives number of rows returned by the query | | getRowData | gives array of object (data) returned by the query | | getFields | gives the array of fields from select part | | getErrorData | gives details regarding error in query execution | | getExecutionStatus | Gives the status(true/false) of query execution | | getExecutionTime | Gives query execution time |

Features

a) Simple query execution interface b) Comprehensive response handling c) Built-in error management d) Field metadata access e) Row count tracking f) Parameterized query support

Usage

Install this module by using below command

$ npm install pg-qry-exec

Import module in your code base

Example (With argument)


import PgQryExecutor from 'pg-qry-exec';
import { Client } from 'pg';

async function executeQuery() {
    const client = new Client({
        // your postgres connection config
    });
    
    try {
        await client.connect();
        const queryExecutor = new PgQryExecutor();
        const query = 'SELECT * FROM users WHERE id = $1';
        const response = await queryExecutor.run(query, userId, client);
        
        if (response.getExecutionStatus()) {
            const data = response.getRowData();
            const rowCount = response.getRowCount();
            console.log(`Retrieved ${rowCount} rows:`, data);
        } else {
            const error = response.getErrorData();
            console.error('Query failed:', error);
        }
    } finally {
        await client.end();
    }
}

Points to Note

a) First argument should be query b) Last argument should be client c) Between you can pass argument if required by the query

Example (Without argument)


import PgQryExecutor from 'pg-qry-exec';
import { Client } from 'pg';

async function executeQuery() {
    const client = new Client({
        // your postgres connection config
    });
    
    try {
        await client.connect();
        const queryExecutor = new PgQryExecutor();
        const query = 'SELECT * FROM users';
        const response = await queryExecutor.run(query, client);
        
        if (response.getExecutionStatus()) {
            const data = response.getRowData();
            const rowCount = response.getRowCount();
            console.log(`Retrieved ${rowCount} rows:`, data);
        } else {
            const error = response.getErrorData();
            console.error('Query failed:', error);
        }
    } finally {
        await client.end();
    }
}

Error Handling

The module includes built-in error handling through the QueryErrorModel:

try {
    const response = await queryExecutor.run(query, client);
    if (!response.getExecutionStatus()) {
        const error = response.getErrorData();
        // Handle error appropriately
    }
} catch (error) {
    // Handle unexpected errors
}

Logging

If you want to log query

    const queryExecutor = new PgQryExecutor(true);

If you want to log argument passed to query

    const queryExecutor = new PgQryExecutor(false,true);

If you want to log both query and argument

    const queryExecutor = new PgQryExecutor(true,true);

If you don't want to log

    const queryExecutor = new PgQryExecutor();

If you want to log query plan

    const queryExecutor = new PgQryExecutor(false,false,true);

The query plan output will show you

a) The sequence of operations PostgreSQL will perform. b) Estimated costs for each operation. c) How tables will be scanned (sequential scan, index scan etc.) d) Join strategies if multiple tables are involved e) Estimated number of rows

Best Practises

Always close database connections:

try {
    // your query execution
} finally {
    await client.end();
}

Check execution status before accessing data:

if (response.getExecutionStatus()) {
    // Safe to access data
    const data = response.getRowData();
} else {
    // Handle error case
}

✨ Authors


🤝 Contributors