Neovim, Helix, and other editors
syntaqlite's language server works with any editor that supports LSP. Configure
your editor to start syntaqlite lsp for SQL files to enable diagnostics and
formatting.
1. Install syntaqlite
If you haven't already:
curl -sSf https://raw.githubusercontent.com/LalitMaganti/syntaqlite/main/tools/syntaqlite | python3 - install
Downloads the latest release to ~/.local/bin. Works on macOS, Linux, and Windows.
mise use github:LalitMaganti/syntaqlite
pip install syntaqlite
brew install LalitMaganti/tap/syntaqlite
cargo install syntaqlite-cli
Verify it runs:
syntaqlite fmt -e "select 1"
2. Configure your editor
Neovim
Add this to your Neovim config (requires nvim-lspconfig):
vim.lsp.config('syntaqlite', {
cmd = { 'syntaqlite', 'lsp' },
filetypes = { 'sql' },
root_markers = { 'syntaqlite.toml', '.git' },
})
vim.lsp.enable('syntaqlite')
After you open a .sql file, syntax errors should be underlined and your usual
LSP format keybinding should format the file.
Helix
Add to ~/.config/helix/languages.toml:
[[language]]
name = "sql"
language-servers = ["syntaqlite"]
[language-server.syntaqlite]
command = "syntaqlite"
args = ["lsp"]
After restarting Helix, open a .sql file to check that diagnostics appear
inline and that :format formats the buffer.
Other LSP clients
The pattern is the same for any editor: set the server command to
syntaqlite lsp and associate it with SQL files. The server communicates over
stdin/stdout using JSON-RPC.
3. Try it out
Create a file called test.sql:
SELEC id, name FROM users;
Open the file in your editor and check that SELEC has a syntax error
diagnostic. Changing it to SELECT should remove the error.
4. Add schema validation
Without a schema, syntaqlite catches syntax errors and function misspellings.
To also catch unknown tables and columns, add a syntaqlite.toml to your
project root:
schema = ["schema.sql"]
Then create schema.sql with your table definitions:
CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT);
Restart the language server (or reopen the editor). Now a query like
SELECT nme FROM users will show a warning with a "did you mean 'name'?"
suggestion.
See project setup for the full configuration reference.