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

postgres

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postgres

Fastest full featured PostgreSQL client for Node.js

  • 3.4.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
367K
decreased by-15.41%
Maintainers
1
Weekly downloads
 
Created

What is postgres?

The 'postgres' npm package is a modern, high-performance PostgreSQL client for Node.js. It provides a simple and efficient way to interact with PostgreSQL databases, supporting both basic and advanced database operations.

What are postgres's main functionalities?

Connecting to a Database

This feature allows you to establish a connection to a PostgreSQL database using a connection string.

const postgres = require('postgres');
const sql = postgres('postgres://username:password@localhost:5432/mydatabase');

Executing Queries

You can execute SQL queries using tagged template literals, which helps in preventing SQL injection attacks.

const result = await sql`SELECT * FROM users WHERE id = ${userId}`;

Parameterized Queries

This feature allows you to use parameterized queries to safely pass variables into your SQL statements.

const result = await sql`SELECT * FROM users WHERE age > ${age}`;

Transactions

You can perform multiple database operations within a transaction to ensure atomicity.

await sql.begin(async sql => {
  await sql`INSERT INTO users (name) VALUES (${name})`;
  await sql`INSERT INTO profiles (user_id, bio) VALUES (${userId}, ${bio})`;
});

Connection Pooling

The package supports connection pooling to manage multiple database connections efficiently.

const sql = postgres({
  host: 'localhost',
  port: 5432,
  username: 'username',
  password: 'password',
  database: 'mydatabase',
  max: 10 // maximum number of connections in the pool
});

Other packages similar to postgres

Keywords

FAQs

Package last updated on 25 Oct 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