One-shot queries
A serverless function executes one database operation per request.
Neon · Const
Neon’s HTTP driver uses the neon() function from @neondatabase/serverless to issue Postgres queries through HTTP fetch requests. It is designed for serverless and edge runtimes, especially for single queries and non-interactive transactions.
The HTTP driver uses the neon() function from @neondatabase/serverless. It returns a tagged-template query function that sends each query through fetch, avoiding a persistent connection and making it suitable for serverless and edge runtimes.
neon(connectionString)| Name | Type | Description |
|---|---|---|
connectionString | string | Neon Postgres connection string, normally supplied from an environment variable. |
A tagged-template query function for executing SQL over HTTP.
neon function provided by the serverless driver.import { neon } from '@neondatabase/serverless';
const sql = neon(process.env.DATABASE_URL!);
const users = await sql`SELECT id, name FROM users WHERE active = ${true}`;
console.log(users);Creates the HTTP query function and executes a parameterized SQL query.
A serverless function executes one database operation per request.
An edge function runs SQL where a persistent TCP connection is unsuitable.
Several statements must run together without interactive session behavior.
The HTTP interface is the neon() function from @neondatabase/serverless. It sends each query as an HTTP fetch request, which avoids maintaining a database connection and is optimized for serverless and edge runtimes.
Follow-up: When should WebSockets be preferred? Use the driver's Pool or Client when the application needs session state or interactive transactions.
neon() returns a query function designed to be used as a tagged template. Interpolated values are handled as query parameters, helping protect against SQL injection.
Follow-up: What is the corresponding limitation? The returned function is intended for tagged-template use rather than ordinary string-built SQL calls.
HTTP is the default choice for single queries and non-interactive transactions. Multiple statements can also be grouped with the driver's transaction function when they do not require interactive session behavior.
Follow-up: What constraint applies to HTTP payloads? Both the request and response are limited to 64 MB.
@neondatabase/serverlessneon()WebSocketsPoolClienttransaction()