# sql-queries

Rule `sonarjs/sql-queries`. SQL queries should not be dynamically formatted

- Source: sonarjs
- Technologies: JavaScript
- Kind: correctness
- Needs type information: yes
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1364 by reach, #665 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/sql-queries` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-2077/) |

## Code examples

### Correct: the rule accepts this

```js
// === MySQL ===
const mysql = require('mysql');
const mycon = mysql.createConnection({ host: host, user: user, password: pass, database: db });
mycon.connect(function(err) {
  mycon.query('SELECT name FROM users WHERE id = ?', [userinput], (err, res) => {});
});

// === PostgreSQL ===
const pg = require('pg');
const pgcon = new pg.Client({ host: host, user: user, password: pass, database: db });
pgcon.connect();
pgcon.query('SELECT name FROM users WHERE id = $1', [userinput], (err, res) => {});
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/sql-queries": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/slow-regex](https://lintradar.dev/rules/sonarjs/slow-regex.md): Regular expressions should not cause catastrophic backtracking
- [sonarjs/stable-tests](https://lintradar.dev/rules/sonarjs/stable-tests.md): Tests should be stable
- [sonarjs/single-character-alternation](https://lintradar.dev/rules/sonarjs/single-character-alternation.md): Single-character alternations in regular expressions should be replaced with character classes
- [sonarjs/stateful-regex](https://lintradar.dev/rules/sonarjs/stateful-regex.md): Regular expressions with the global flag should be used with caution
- [sonarjs/single-char-in-character-classes](https://lintradar.dev/rules/sonarjs/single-char-in-character-classes.md): Character classes in regular expressions should not contain only one character
- [sonarjs/strict-transport-security](https://lintradar.dev/rules/sonarjs/strict-transport-security.md): HTTP Strict-Transport-Security policy should not be disabled

---

Web page: https://lintradar.dev/rules/sonarjs/sql-queries. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
