| layout | doc |
|---|
SafeQL is compatible with Postgres.js. SafeQL is built on top of Postgres.js!
::: tabs key:eslintrc
== Flat Config
// 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}[]" }
],
})
);== Legacy Config
- Add
@ts-safeql/eslint-pluginto your ESLint plugins:
// .eslintrc.json
{
"plugins": [..., "@ts-safeql/eslint-plugin"],
...
}
- Add
@ts-safeql/check-sqlto your rules and set theconnectionsoption:
// .eslintrc.json
{
// ...
"rules": {
// ...
"@ts-safeql/check-sql": [
"error",
{
"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:
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 // [!code error]
// After bug fix:
const query = sql`SELECT id FROM users`
~~~ Error: Query is missing type annotation // [!code error]
// After: ✅
const query = sql<{ id: number; }[]>`SELECT id FROM users`