You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@vercel/postgres

Package Overview
Dependencies
Maintainers
8
Versions
46
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vercel/postgres

Connect to Vercel Postgres databases on the Edge


Version published
Weekly downloads
65K
decreased by-22.73%
Maintainers
8
Created
Weekly downloads
 

Readme

Source

@vercel/postgres 🚧

A client that works with Vercel Postgres.

Quick Start

Install

npm install @vercel/postgres

Basic Usage

Automatically Read Environment Variables

Default Export

import postgres from '@vercel/postgres';

await postgres.query('SELECT * from POSTS WHERE likes > 100;');

Named Export

import { postgres } from '@vercel/postgres';

await postgres.query('SELECT * from POSTS WHERE likes > 100;');
Set Connection String Manually (Client or Pool)
import { createClient, createPool } from '@vercel/postgres';

const client = createClient({
  connectionString: process.env.SOME_POSTGRES_CONNECTION_STRING,
});

await client.query('SELECT * from POSTS WHERE likes > 100;');

const pool = createPool({
  connectionString: process.env.SOME_POSTGRES_CONNECTION_STRING,
});

await pool.query('SELECT * from POSTS WHERE likes > 100;');

Parameterized Query

import { postgres } from '@vercel/postgres';

await postgres.query('SELECT * from POSTS WHERE author=$1;', ['rauchg']);

Connection Config

When using the createClient or createPool functions, you can pass in additional options to configuration object alongside the connection string that conforms to PostgresConfig or PostgresPoolConfig, respectively:

export interface PostgresConfig {
  connectionString: string;
  keepAlive?: boolean | undefined;
  statement_timeout?: false | number | undefined;
  query_timeout?: number | undefined;
  keepAliveInitialDelayMillis?: number | undefined;
  idle_in_transaction_session_timeout?: number | undefined;
  application_name?: string | undefined;
  connectionTimeoutMillis?: number | undefined;
  max?: number | undefined;
  min?: number | undefined;
  idleTimeoutMillis?: number | undefined;
  log?: ((...messages: unknown[]) => void) | undefined;
  allowExitOnIdle?: boolean | undefined;
  maxUses?: number | undefined;
}

export interface PostgresPoolConfig extends PostgresConfig {
  max?: number | undefined;
  min?: number | undefined;
  idleTimeoutMillis?: number | undefined;
  log?: ((...messages: unknown[]) => void) | undefined;
  allowExitOnIdle?: boolean | undefined;
  maxUses?: number | undefined;
}

Documentation

The @vercel/postgres package uses the pg under the hood. For more detailed documentation, checkout node-postgres.

FAQs

Package last updated on 18 Apr 2023

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc