Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pg-pool

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-pool

Connection pool for node-postgres

  • 3.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.7M
decreased by-11.03%
Maintainers
1
Weekly downloads
 
Created

What is pg-pool?

The pg-pool npm package is a connection pool manager for PostgreSQL, built on top of the 'pg' library. It allows you to manage multiple database connections efficiently, providing features like connection pooling, transaction management, and error handling.

What are pg-pool's main functionalities?

Connection Pooling

This feature allows you to create a pool of connections to the PostgreSQL database. The pool manages the connections, reusing them for multiple queries to improve performance.

const { Pool } = require('pg');
const pool = new Pool({
  user: 'dbuser',
  host: 'database.server.com',
  database: 'mydb',
  password: 'secretpassword',
  port: 5432,
});

pool.query('SELECT NOW()', (err, res) => {
  console.log(err, res);
  pool.end();
});

Transaction Management

This feature allows you to manage transactions, ensuring that a series of database operations either all succeed or all fail, maintaining data integrity.

const { Pool } = require('pg');
const pool = new Pool();

(async () => {
  const client = await pool.connect();
  try {
    await client.query('BEGIN');
    const res = await client.query('INSERT INTO users(name) VALUES($1) RETURNING id', ['brianc']);
    const insertPhotoText = 'INSERT INTO photos(user_id, photo_url) VALUES ($1, $2)';
    const insertPhotoValues = [res.rows[0].id, 's3.bucket.foo'];
    await client.query(insertPhotoText, insertPhotoValues);
    await client.query('COMMIT');
  } catch (e) {
    await client.query('ROLLBACK');
    throw e;
  } finally {
    client.release();
  }
})();

Error Handling

This feature provides robust error handling, allowing you to catch and handle errors that occur during query execution.

const { Pool } = require('pg');
const pool = new Pool();

pool.query('SELECT * FROM non_existent_table', (err, res) => {
  if (err) {
    console.error('Error executing query', err.stack);
  } else {
    console.log(res.rows);
  }
  pool.end();
});

Other packages similar to pg-pool

Keywords

FAQs

Package last updated on 17 Sep 2024

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