Skip to content

Neon.Branch reference

Source: src/Neon/Branch.ts

A branch of a Neon project.

Branches are first-class, copy-on-write copies of a parent branch — they share storage with the parent until the new branch starts diverging.

Branch: Branching from a project’s default branch

Section titled “Branch: Branching from a project’s default branch”
const project = yield* Neon.Project("my-project");
const dev = yield* Neon.Branch("dev-branch", { project });
const dev = yield* Neon.Branch("dev", { project });
const featureBranch = yield* Neon.Branch("feature", {
project,
parentBranch: dev,
});
const branch = yield* Neon.Branch("at-lsn", {
project,
parentLsn: "0/3FA01B0",
});
const featureBranch = yield* Neon.Branch("feature", {
project,
migrations: "./migrations",
});

Source: src/Neon/Connect.ts

Connect to a Branch or a Project’s default database from a Function, Worker, Lambda, or another Platform host. Same-branch Neon Functions use the injected DATABASE_URL and DATABASE_URL_UNPOOLED; local Functions and other hosts receive namespaced database secrets, never the deployment account API key.

Accessors are lazy and redacted. SQL.Postgres and Drizzle.Postgres create their connections in request scope, not when this binding is initialized.

Effect.gen(function* () {
const db = yield* Neon.Connect(branch);
const sql = yield* SQL.Postgres({ url: db.connectionString });
return { fetch: Effect.gen(function* () {
return yield* HttpServerResponse.json(yield* sql`SELECT 1 AS value`);
}) };
}).pipe(Effect.provide(Neon.ConnectHttp));
const api = yield* Neon.Function("Api", {
branch: applicationBranch,
main: "./api.ts",
env: Neon.connectEnv(databaseBranch),
});

Native same-branch Neon Functions already have DATABASE_URL and DATABASE_URL_UNPOOLED and need no binding. connectEnvKeys gives native applications the names used by connectEnv for cross-host connections.