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

pg-database-manager

v1.0.4

Published

A streamlined toolkit for PostgreSQL database operations, offering connection management, CRUD operations, and schema handling with ease.

Downloads

12

Readme

DBConnection Class Documentation

Overview

The DBConnection class is designed to facilitate interactions with a PostgreSQL database, providing methods for connecting to the database, performing CRUD operations, and fetching schema information.

Constructor

DBConnection()

Initializes a new instance of the DBConnection class.

Methods

async ConnectPG(login)

  • Establishes a connection to the PostgreSQL database.
  • Parameters:
    • login (Object): Configuration for database connection.
  • Returns: Promise that resolves upon establishing the connection.

async GetPG(table, where = "", values = [], select = "*", output = false)

  • Retrieves data from a specified table.
  • Parameters:
    • table (String): Table name.
    • where (String, optional): WHERE clause.
    • values (Array, optional): Parameterized query values.
    • select (String, optional): Columns to select.
    • output (Boolean, optional): Modify query result.
  • Returns: Promise with the query result.

async SetPG(array, whereValues, table)

  • Updates data in a specified table.
  • Parameters:
    • array (Array): Data to update.
    • whereValues (Array|String): Update criteria.
    • table (String): Table name.
  • Returns: Promise that resolves upon completion.

async InsertPG(array, table, toReturn = "")

  • Inserts data into a specified table.
  • Parameters:
    • array (Array): Data to insert.
    • table (String): Table name.
    • toReturn (String, optional): Columns to return.
  • Returns: Promise with inserted data or success message.

async DeletePG(table, where = "", values = [], safety = true)

  • Deletes data from a specified table.
  • Parameters:
    • table (String): Table name.
    • where (String, optional): WHERE clause.
    • values (Array, optional): Parameterized query values.
    • safety (Boolean, optional): Execute safety check.
  • Returns: Promise that resolves upon completion.

async getSchemaPG(table)

  • Fetches schema information for a specified table.
  • Parameters:
    • table (String): Table name.
  • Returns: Promise with schema details.

async DisconnectPG()

  • Disconnects from the PostgreSQL database.
  • Returns: Promise that resolves upon disconnection.

Example Usage

const db = new DBConnection();

// Establish a connection to the database
const loginConfig = {
    user: 'your_username',
    password: 'your_password',
    host: 'localhost',
    port: 5432,
    database: 'your_database'
};
await db.ConnectPG(loginConfig);

// Retrieve data from a table
const userData = await db.GetPG('users', 'age > $1', [18], 'name, age');
console.log('Users above 18:', userData.rows);

// Insert data into a table
const newUser = { name: 'Alice', age: 25 };
await db.InsertPG([newUser], 'users');
console.log('New user inserted.');

// Update data in a table
const updateCriteria = ['name']; // Match users with name "Alice"
const updatedData = {name:"Alice", age: 26 };
await db.SetPG([updatedData], updateCriteria , 'users');
console.log('User data updated.');

// Delete data from a table
const deleteCriteria = ['Bob']; // Match users with name "Bob"
await db.DeletePG('users', 'name = $1', deleteCriteria);
console.log('User data deleted.');

// Fetch schema information for a table
const schemaInfo = await db.getSchemaPG('users');
console.log('Schema Information:', schemaInfo);

// Disconnect from the database
await db.DisconnectPG();
console.log('Disconnected from the database.');

This documentation provides a comprehensive guide to utilizing the DBConnection class for managing database interactions within a Node.js application.