← Docs

Next.js

Next.js doesn't have a built-in database layer. You use Gold Lapel's connection wrapper directly — one module, any server-side context.

Install

npm install goldlapel pg
# or: npm install goldlapel postgres
# or: npm install goldlapel @vercel/postgres

Gold Lapel is a driver-agnostic wrapper — install whichever Postgres driver your app uses alongside it. pg is the most common; postgres (postgres.js) and @vercel/postgres also work.

Setup

Create a connection module at lib/db.js:

import * as goldlapel from 'goldlapel';
import pg from 'pg';

const gl = await goldlapel.start(process.env.DATABASE_URL);
const pool = new pg.Pool({ connectionString: gl.url });

export { gl, pool };

App Router

Use the connection in an API route (app/api/users/route.js):

import { pool } from '@/lib/db';

export async function GET() {
  const users = await pool.query('SELECT * FROM users');
  return Response.json(users.rows);
}

Pages Router

Use the connection in getServerSideProps:

import { pool } from '@/lib/db';

export async function getServerSideProps() {
  const users = await pool.query('SELECT * FROM users');
  return { props: { users: users.rows } };
}

Server-Side Only

Gold Lapel only runs server-side. In Next.js, this means API routes, getServerSideProps, and Server Components — never in client components.

ORMs

Using Prisma? See @goldlapel/prisma. Using Drizzle? See @goldlapel/drizzle.