https://github.com/barklan/inline_sql_syntax
Highlight and lint inline SQL strings.
https://github.com/barklan/inline_sql_syntax
linter mysql postgres sql vscode vscode-extension
Last synced: about 1 month ago
JSON representation
Highlight and lint inline SQL strings.
- Host: GitHub
- URL: https://github.com/barklan/inline_sql_syntax
- Owner: barklan
- License: mit
- Created: 2021-11-21T18:18:48.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-12-01T22:06:14.000Z (4 months ago)
- Last Synced: 2025-12-04T12:33:35.694Z (4 months ago)
- Topics: linter, mysql, postgres, sql, vscode, vscode-extension
- Language: TypeScript
- Homepage: https://marketplace.visualstudio.com/items?itemName=qufiwefefwoyn.inline-sql-syntax
- Size: 712 KB
- Stars: 67
- Watchers: 3
- Forks: 35
- Open Issues: 47
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Inline SQL 
> Also available in [Open VSX Registry](https://open-vsx.org/extension/qufiwefefwoyn/inline-sql-syntax)

Highlight and lint inline SQL strings.
Supported languages are **Python**, **Go**, **JavaScript**, **TypeScript**, **Ruby**, **Java**, **C#**, **Rust**, **PHP**, **Lua**.
Syntax highlighting works for strings starting with `--sql` or any of
the `SELECT`, `INSERT`, `INTO`, `DELETE`, `UPDATE`, `CREATE TABLE`.
Also works with ES6 Template Strings:
```javascript
const query = sql`
select * from book;
`;
```
**Linting and diagnostics powered entirely by awesome
[joereynolds/sql-lint](https://github.com/joereynolds/sql-lint) and works for
multiline strings that start with either \`--sql (backtick followed by `--sql`),
`"--sql` or `"""--sql`.**
## Contributors
jwhitaker-swiftnav
Connor Bren
Ferenc Tamás
Gunnar Sv Sigurbjörnsson
Jon Wolfe
Titouan CREACH
## Safety
The proper way to sanitize data for insertion into your database is to
use placeholders for all variables to be inserted into your SQL strings.
In other words, NEVER do this (Python example):
```python
query = f"INSERT INTO foo (bar, baz) VALUES ( {variable1}, {variable2} )";
```
Instead, use `$` placeholders (or `?` in some databases):
```python
query = "INSERT INTO foo (bar, baz) VALUES ( $1, $2 )";
```
And then pass the variables to be replaced when you execute the query.
For example with [pgx](https://github.com/JackC/pgx) (Go example):
```go
err = conn.QueryRow(
context.Background(),
"select name, weight from widgets where id=$1",
42,
).Scan(&name, &weight)
```
## Integration with real database
Integration with real database is available and controlled through VSCode options:
```json
{
"inlineSQL.enableDBIntegration": true,
"inlineSQL.dbDriver": "postgres",
"inlineSQL.dbHost": "localhost",
"inlineSQL.dbPort": 5432,
"inlineSQL.dbUser": "postgres",
"inlineSQL.dbPassword": "postgres"
}
```
## Examples
### Python

### JavaScript/TypeScript

### Go


Python
JavaScript/TypeScript
Ruby
Java
## Limitations
### Semantic highlighting
Highlighting does not work with semantic token highlighting enabled (feature provided by some LSP servers).
Currently gopls semantic token highlighting (option `gopls.ui.semanticTokens` - off by default)
overrides extension's syntax.
#### gopls
```json
{
"gopls.ui.semanticTokens": false
}
```
#### rust-analyzer
```json
{
"rust-analyzer.highlighting.strings": false
}
```
#### `C#`
```json
{
"csharp.semanticHighlighting.enabled": false
}
```
## Motivation
This small extension is meant to help those who don't use ORM and don't like SQL builders
like [squirrel](https://github.com/Masterminds/squirrel),
but still want inline sql in their code to be something more than magic strings,
helping to avoid small bugs and typos almost instantly.
## Related
- [joereynolds/sql-lint](https://github.com/joereynolds/sql-lint) - Used for linting.
- [joe-re/sql-language-server](https://github.com/joe-re/sql-language-server) - SQL Language Server, consider it if you use separate files for sql.
- [cmoog/vscode-sql-notebook](https://github.com/cmoog/vscode-sql-notebook) - Open SQL files as VSCode Notebooks.
- [pushqrdx/vscode-inline-html](https://github.com/pushqrdx/vscode-inline-html) - ES6 Template Strings inline HTML.