Skip to content

SafeQL 🤝 Postgres.js

SafeQL is compatible with Postgres.js. SafeQL is built on top of Postgres.js!

js
// eslint.config.js

import safeql from "@ts-safeql/eslint-plugin/config";
import tseslint from "typescript-eslint";

export default tseslint.config(
  // ...
  safeql.configs.connections({
    // ... (read more about configuration in the API docs)
    targets: [
      // this will lint syntax that matches "sql`...`"
      { tag: "sql", transform: "{type}[]" }
    ],
  })
);

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

typescript
import { sql } from "postgres";
import { myClient } from "./myClient"; // Read the note above

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

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

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