Neon.Branch reference
Branch
Section titled “Branch”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 });Branch: Branching from another branch
Section titled “Branch: Branching from another branch”const dev = yield* Neon.Branch("dev", { project });const featureBranch = yield* Neon.Branch("feature", { project, parentBranch: dev,});Branch: Point-in-time branches
Section titled “Branch: Point-in-time branches”const branch = yield* Neon.Branch("at-lsn", { project, parentLsn: "0/3FA01B0",});Branch: Migrations on a branch
Section titled “Branch: Migrations on a branch”const featureBranch = yield* Neon.Branch("feature", { project, migrations: "./migrations",});Connect
Section titled “Connect”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.
Connect: Querying Postgres
Section titled “Connect: Querying Postgres”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));Connect: Native applications
Section titled “Connect: Native applications”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.