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

@vercel/postgres

Package Overview
Dependencies
Maintainers
8
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vercel/postgres - npm Package Compare versions

Comparing version 0.1.0-canary.29 to 0.1.2

dist/chunk-BZXLCAAL.js

2

dist/index-node.js

@@ -1,1 +0,1 @@

import{a as t,b as f,c as m,d as e,e as i,f as n,g as p}from"./chunk-MIUFAVOQ.js";import{neonConfig as o}from"@neondatabase/serverless";import r from"ws";o&&(o.webSocketConstructor=r);export{f as VercelClient,e as VercelPool,m as createClient,i as createPool,p as db,t as postgresConnectionString,n as sql};
import{a as t,b as f,c as m,d as e,e as i,f as n,g as p}from"./chunk-BZXLCAAL.js";import{neonConfig as o}from"@neondatabase/serverless";import r from"ws";o&&(o.webSocketConstructor=r);export{f as VercelClient,e as VercelPool,m as createClient,i as createPool,p as db,t as postgresConnectionString,n as sql};

@@ -57,9 +57,8 @@ import { ClientConfig, PoolConfig, ClientBase, QueryResultRow, QueryResult, Client, Pool } from '@neondatabase/serverless';

declare function sql<O extends QueryResultRow>(strings: TemplateStringsArray, ...values: Primitive[]): Promise<QueryResult<O>>;
declare type ConnectionStringType = 'pool' | 'direct';
declare function postgresConnectionString(type?: ConnectionStringType): string | undefined;
declare const db: VercelPool;
declare const sql: VercelPool & (<O extends QueryResultRow>(strings: TemplateStringsArray, ...values: Primitive[]) => Promise<QueryResult<O>>);
declare const db: VercelPool & (<O extends QueryResultRow>(strings: TemplateStringsArray, ...values: Primitive[]) => Promise<QueryResult<O>>);
export { VercelClient, VercelClientBase, VercelPool, VercelPoolClient, VercelPostgresClientConfig, VercelPostgresPoolConfig, createClient, createPool, db, postgresConnectionString, sql };

@@ -1,1 +0,1 @@

import{a,b,c,d,e,f,g}from"./chunk-MIUFAVOQ.js";export{b as VercelClient,d as VercelPool,c as createClient,e as createPool,g as db,a as postgresConnectionString,f as sql};
import{a,b,c,d,e,f,g}from"./chunk-BZXLCAAL.js";export{b as VercelClient,d as VercelPool,c as createClient,e as createPool,g as db,a as postgresConnectionString,f as sql};
{
"name": "@vercel/postgres",
"version": "0.1.0-canary.29",
"version": "0.1.2",
"description": "Connect to Vercel Postgres databases on the Edge",

@@ -11,3 +11,3 @@ "homepage": "https://vercel.com",

},
"license": "MIT",
"license": "Apache-2.0",
"type": "module",

@@ -14,0 +14,0 @@ "exports": {

@@ -1,2 +0,2 @@

# @vercel/postgres 🚧
# @vercel/postgres

@@ -15,43 +15,43 @@ A client that works with Vercel Postgres.

### No-Config
### Importing
If the environment variables provided by your Vercel project are all the configuration you need, you can use the config-less `sql` import:
```typescript
// Don't need any custom config?:
import { sql } from '@vercel/postgres';
// `sql` is already set up and ready to go; no further action needed
const likes = 100;
const { rows, fields } = await sql`SELECT * FROM posts WHERE likes > ${likes};`;
```
// Need to customize your config?:
import { createPool } from '@vercel/postgres';
const pool = createPool({
/* config */
});
This will safely substitute the JavaScript value into the query by using database parameters. The above query translates to:
```typescript
await pool.query('SELECT * FROM posts WHERE likes > $1;', [100]);
// Need a single client?:
import { createClient } from '@vercel/postgres';
const client = createClient({
/* config */
});
```
### Create a Pool
### Querying
If you need a `pg` `Pool` object, you can use the `createPool` function.
Automatically uses `process.env.POSTGRES_URL`:
```typescript
import { createPool } from '@vercel/postgres';
// no-config
import { sql } from '@vercel/postgres';
const pool = createPool();
const id = 100;
// The same tagged literal function as the no-config option, but attached to your pool
const likes = 100;
const { rows, fields } =
await pool.sql`SELECT * FROM posts WHERE likes > ${likes};`;
// A one-shot query
const { rows } = await sql`SELECT * FROM users WHERE id = ${userId};`;
// or use the query method from `pg`
const likes = 100;
const { rows, fields } = await pool.query(
'SELECT * from posts WHERE likes > $1;',
[likes],
);
// Multiple queries on the same connection (improves performance)
// warning: Do not share clients across requests and be sure to release them!
const client = await sql.connect();
const { rows } = await client.sql`SELECT * FROM users WHERE id = ${userId};`;
await client.sql`UPDATE users SET status = 'satisfied' WHERE id = ${userId};`;
client.release();
```
The `sql` import in the query above is just a modified `Pool` object (that's why you can call it). If you're running a custom config with `createPool`, the same functionality is available as `pool.sql`.
To specify a connection string:

@@ -71,40 +71,6 @@

### Create a Client
### A note on edge environments
If you need a `pg` `Client` object, you can use the `createClient` function.
In edge environments, IO connections cannot be reused between requests. To allow your `Pool`s to continue to function, we set `maxUses` to 1 when running on the edge (otherwise the `Pool` might hold on to a `Client` used in one request and try to use it again in another). Unfortunately, this means the `Pool` _also_ can't reuse the connection _within_ the request. For this reason, if you're firing more than one database query to serve a single request in your app, we recommend obtaining a `Client` from `Pool.connect`, using that `Client` to query the database, and then releasing it.
Automatically uses `process.env.POSTGRES_URL_NON_POOLING`:
```typescript
import { createClient } from '@vercel/postgres';
/**
* Clients cannot be reused, so you have to create them, connect them, and disconnect them
* per query. This is why you should use a pool unless you explicitly need a single client.
*/
async function queryPosts() {
const client = createClient();
await client.connect();
try {
const likes = 100;
const { rows, fields } =
await client.sql`SELECT * FROM posts WHERE likes > ${likes};`;
} finally {
await client.end();
}
}
```
To specify a connection string:
```typescript
import { createClient } from '@vercel/postgres';
const client = createClient({
connectionString: process.env.SOME_POSTGRES_CONNECTION_STRING,
});
```
### Get the connection url

@@ -111,0 +77,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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