Socket
Socket
Sign inDemoInstall

@types/pg

Package Overview
Dependencies
12
Maintainers
1
Versions
94
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @types/pg

TypeScript definitions for pg


Version published
Weekly downloads
2.4M
decreased by-17.87%
Maintainers
1
Install size
2.28 MB
Created
Weekly downloads
 

Package description

What is @types/pg?

The @types/pg package provides TypeScript type definitions for the pg (node-postgres) library, which is a collection of Node.js modules for interfacing with your PostgreSQL database. It enables TypeScript developers to work with pg more efficiently by offering compile-time type checking and IntelliSense support in code editors.

What are @types/pg's main functionalities?

Client Connection

This feature allows you to connect to a PostgreSQL database using the Client class. The code sample demonstrates how to create a new client, connect to the database, execute a simple query, and then close the connection.

import { Client } from 'pg';

const client = new Client();
await client.connect();
await client.query('SELECT NOW()');
await client.end();

Pool Management

This feature enables efficient management of a pool of connections to the PostgreSQL database. The code sample shows how to create a pool, acquire a client from the pool, execute a query, release the client back to the pool, and finally close the pool.

import { Pool } from 'pg';

const pool = new Pool();
const client = await pool.connect();
try {
  const res = await client.query('SELECT NOW()');
} finally {
  client.release();
}
await pool.end();

Query with Parameters

This feature demonstrates how to execute a parameterized query to prevent SQL injection. The code sample illustrates inserting data into a table using parameters for the values.

import { Client } from 'pg';

const client = new Client();
await client.connect();
const text = 'INSERT INTO users(name, email) VALUES($1, $2) RETURNING *';
const values = ['Brian', 'brian@example.com'];
const res = await client.query(text, values);
await client.end();

Other packages similar to @types/pg

Readme

Source

Installation

npm install --save @types/pg

Summary

This package contains type definitions for pg (https://github.com/brianc/node-postgres).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/pg.

Additional Details

Credits

These definitions were written by Phips Peter, and Ravi van Rooijen.

FAQs

Last updated on 09 Apr 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc