Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
@vercel/postgres
Advanced tools
A client that works with Vercel Postgres.
Note: If you want to use an ORM instead of writing your own queries, see @vercel/postgres-kysely.
pnpm install @vercel/postgres
If you need a pg
Pool
object, you can use the createPool
function.
Automatically uses process.env.POSTGRES_URL
:
import { createPool } from '@vercel/postgres';
const pool = createPool();
const { rows, fields } = await pool.query(
'SELECT * from POSTS WHERE likes > 100;',
);
To specify a connection string:
import { createPool } from '@vercel/postgres';
const pool = createPool({
connectionString: process.env.SOME_POSTGRES_CONNECTION_STRING,
});
const { rows, fields } = await pool.query(
'SELECT * from POSTS WHERE likes > 100;',
);
If you need a pg
Client
object, you can use the createClient
function.
Automatically uses process.env.POSTGRES_URL_NON_POOLING
:
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 { rows, fields } = await client.query(
'SELECT * from POSTS WHERE likes > 100;',
);
} finally {
await client.end();
}
}
To specify a connection string:
import { createClient } from '@vercel/postgres';
const client = createClient({
connectionString: process.env.SOME_POSTGRES_CONNECTION_STRING,
});
If you just want the connection URL, you can call postgresConnectionString(type: 'pool' | 'direct'): string;
. This will read from your environment variables. For the pool
type, it will look for the POSTGRES_URL
environment variables. For the direct
type, it will look for the POSTGRES_URL_NON_POOLING
environment variables.
import { postgresConnectionString } from '@vercel/postgres';
const pooledConnectionString = postgresConnectionString('pool');
const directConnectionString = postgresConnectionString('direct');
When using the createClient
or createPool
functions, you can pass in additional options alongside the connection string that conforms to VercelPostgresClientConfig
or VercelPostgresPoolConfig
.
The @vercel/postgres
package uses the pg
package. For
more detailed documentation, checkout node-postgres.
FAQs
Connect to Vercel Postgres databases on the Edge
The npm package @vercel/postgres receives a total of 34,183 weekly downloads. As such, @vercel/postgres popularity was classified as popular.
We found that @vercel/postgres demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
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.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.