Skip to content

SafeQL ❤️ @vercel/postgres

SafeQL supports @vercel/postgres out of the box.


Check out @ts-safeql-demos/vercel-postgres for a working example.

  1. Add @ts-safeql/eslint-plugin into your ESLint plugins and configure the rule it with useConfigFile:
// .eslintrc.json
  "plugins": [
    // ...
  "rules": {
    "@ts-safeql/check-sql": ["error", { "useConfigFile": true }]
  1. Create a file called safeql.config.ts:


This example uses the development DATABASE_URL environment variable, but you can configure it according to your needs.

// safeql.config.ts

import { defineConfig } from "@ts-safeql/eslint-plugin";
import dotenv from "dotenv";

dotenv.config({ path: ".env.development.local" });

export default defineConfig({
  connections: {
    databaseUrl: process.env.POSTGRES_URL,
    targets: [{ tag: "?(client.)sql" }],

Once you've set up your configuration, you can start linting your queries:

import { db, sql } from "@vercel/postgres";

// Before:
const query = client.sql`SELECT idd FROM users`;
                     ~~~ Error: column "idd" does not exist 

// After bug fix:
const query = client.sql`SELECT id FROM users`;
              ~~~~~~~~~~ Error: Query is missing type annotation

// ✅ After:
const query = client.sql<{ id: number; }>`SELECT id FROM users`;

// ✅ Vercel's sql tag is also supported:
const query = sql<{ id: number; }>`SELECT id FROM users`;