Single HTTP query
Run an isolated database read or write from a serverless or edge handler.
Neon · Function
Neon's neon() function creates a tagged-template query function for running Postgres SQL over HTTP. It supports parameter-safe interpolation and exposes a transaction helper for multiple queries in one non-interactive transaction.
The neon() function accepts a database connection string and returns a query function. Invoke that function with a tagged template literal containing SQL and interpolated values; the driver sends the query over HTTP and returns the result rows. The returned query function also exposes transaction for multiple statements in one non-interactive transaction.
neon(connectionString)| Name | Type | Description |
|---|---|---|
connectionString | string | A Neon Postgres connection string, commonly supplied from process.env.DATABASE_URL. |
query | tagged template | SQL supplied as a tagged template literal, with interpolated values treated as parameters. |
A tagged-template query function that resolves to query result rows and exposes transaction(queriesOrFn, options).
neon() is itself the callable query interface.transaction when several queries need one non-interactive transactional execution.import { neon } from '@neondatabase/serverless';
const sql = neon(process.env.DATABASE_URL!);
const rows = await sql`SELECT NOW() AS current_time`;
console.log(rows);Creates a Neon query function and executes a parameter-safe SQL template query.
Run an isolated database read or write from a serverless or edge handler.
Execute several related statements without opening an interactive session.
Insert request-derived values while avoiding SQL string concatenation.
neon() function return?neon() creates a query function configured with the database connection string. The query function is used as a tagged template, and the driver sends each HTTP query through fetch.
Follow-up: How are multiple statements grouped atomically? Use the query function's transaction(queriesOrFn, options) property to execute them in one non-interactive transaction.
Use a tagged template such as sqlSELECT NOW(). Interpolated values are handled as parameters, and the documentation states that tagged-template-only usage improves protection against SQL injection.
Follow-up: Why not concatenate user input into the SQL text? Concatenation changes data into executable SQL text, whereas interpolation through the tagged template preserves parameterization.
The driver defaults to HTTP for queries. This is optimized for single queries and multiple queries in a non-interactive transaction, while the returned query function also provides a transaction helper.
Follow-up: What constraint follows from HTTP execution? Code requiring an interactive session should use an appropriate connection-oriented driver rather than assuming each request shares session state.
transactionneonNeon serverless driverHTTP