SafeQL 💪 Sequelize ​
SafeQL is compatible with Sequelize which supports raw queries as well!
PLEASE NOTE
Sequelize doesn't come with a built-in SQL template tag (sql``
).
Thus, you'll need to install @ts-safeql/sql-tag in order to use SafeQL with Sequelize.
If you prefer using a different SQL template tag library, that's fine too! see sql-template-strings and sql-template-tag
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 "sequelize.query(sql`...`)"
{ wrapper: "sequelize.query" },
],
})
);
Once you've set up your configuration, you can start linting your queries:
typescript
import { Sequelize } from "sequelize";
const sequelize = new Sequelize();
// Before
const query = sequelize.query("SELECT idd FROM users");
~~~ Error: column "idd" does not exist
// After bug fix
const query = sequelize.query("SELECT id FROM users");
~~~~~~~~~~~~~~~ Error: Query is missing type annotation
// After: ✅
const query = sequelize.query(sql`SELECT id FROM users`);