@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
import { createClient } from '@vercel/postgres';
const postgres = createClient(process.env.SOME_POSTGRES_CONNECTION_STRING);
await postgres.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
function, you can pass an optional configuration object that conforms to PostgresConfig
:
export interface PostgresConfig {
connectionString?: string | undefined;
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;
}
Documentation
The @vercel/postgres
package uses the pg
under the hood. For
more detailed documentation, checkout node-postgres.