Skip to content

Netlify

PerSQL gives a Netlify site its own SQLite database on the edge. You provision a database, set three environment variables, and query with the PerSQL SDK from a Netlify Function. Every Netlify Deploy Preview can get its own isolated branch database.

  1. Go to netlify.persql.com/connect, sign in, and provision a database. You get three values:

    VariableExampleSecret
    PERSQL_API_URLhttps://api.persql.comno
    PERSQL_DATABASE<namespace>/<db-slug>no
    PERSQL_TOKENpsql_live_…yes

    The token is admin-scoped to that one database (so your app can run its own migrations) and nothing else.

  2. Set them under Site configuration → Environment variables, share them across sites with team-level variables, or set them from the CLI with netlify env:set PERSQL_TOKEN ….

  3. Query from a Netlify Function:

    import { PerSQL } from "@persql/sdk";
    const db = new PerSQL({
    token: process.env.PERSQL_TOKEN,
    baseURL: process.env.PERSQL_API_URL,
    }).database(process.env.PERSQL_DATABASE);
    export default async () => {
    const { data } = await db.query("SELECT 1 AS ok");
    return Response.json(data);
    };

The netlify-starter repo is a minimal Netlify Function backed by PerSQL, with a netlify.toml that declares the three variables under [template.environment] so Netlify prompts for them:

Deploy to Netlify

Click it, then paste the values from the connect page when Netlify prompts.

Point a coding agent at the Netlify MCP for the per-PR recipe:

https://netlify.persql.com/mcp

Authenticate with a PerSQL bearer token. preview_recipe returns the snippet that spawns a preview-pr-<n> branch during a Deploy Preview build (Netlify sets REVIEW_ID to the PR number) and the GitHub Action that cleans it up on close; preview_list shows the active previews. Netlify runs no build when a PR closes, so cleanup rides the branch TTL or a pull_request: closed Action.