syntaqlite
A parser, formatter, validator, and language server for SQLite SQL, built on SQLite's own grammar and tokenizer. If SQLite accepts it, syntaqlite parses it. If SQLite rejects it, so does syntaqlite.
Docs · Playground · VS Code Extension
Note: syntaqlite is at 0.x. APIs and CLI flags may change before 1.0.
Why syntaqlite
Most SQLite tools build a generic SQL parser and bolt SQLite on as a "flavor" with hand-written grammars, regex-based tokenizers, or subsets that approximate the language. That falls apart because SQLite has a deep surface area of syntax that generic parsers don't handle.
syntaqlite uses SQLite's own Lemon-generated grammar and tokenizer, compiled from C. The parser doesn't approximate SQLite; it is SQLite's grammar compiled into a reusable library.
SQLite SQL is also not one fixed language. It has 22 compile-time flags that change what syntax the parser accepts, another 12 that gate built-in functions, and the language evolves across versions. Because SQLite is embedded, you can't assume everyone is on the latest version (Android 15 ships SQLite 3.44.3, seven major versions behind latest). syntaqlite tracks all of this:
syntaqlite --sqlite-version 3.32.0 validate \
-e "DELETE FROM users WHERE id = 1 RETURNING *;"
error: syntax error near 'RETURNING'
--> <stdin>:1:32
|
1 | DELETE FROM users WHERE id = 1 RETURNING *;
| ^~~~~~~~~
RETURNING was added in SQLite 3.35.0; Android 13 still ships SQLite 3.32.2.
We've tested against ~396K statements from SQLite's upstream test suite with ~99.7% agreement on parse acceptance. See the detailed comparison for how syntaqlite stacks up against other tools.
What it does
Validate (docs)
Finds unknown tables, columns, and functions against your schema, the same errors sqlite3_prepare would catch but without needing a database. Unlike sqlite3, syntaqlite finds all errors in one pass:
CREATE TABLE orders (id, status, total, created_at);
WITH
monthly_stats(month, revenue, order_count) AS (
SELECT strftime('%Y-%m', o.created_at), SUM(o.total)
FROM orders o WHERE o.status = 'completed'
GROUP BY strftime('%Y-%m', o.created_at)
)
SELECT ms.month, ms.revenue, ms.order_count,
ROUDN(ms.revenue / ms.order_count, 2) AS avg_order
FROM monthly_stats ms;
sqlite3 stops at the first error and misses the function typo entirely:
Error: in prepare, table monthly_stats has 2 values for 3 columns
syntaqlite finds both the CTE column count mismatch and the ROUDN typo, with source locations and suggestions:
error: table 'monthly_stats' has 2 values for 3 columns
|
2 | monthly_stats(month, revenue,
| ^~~~~~~~~~~~~
warning: unknown function 'ROUDN'
|
14 | ROUDN(ms.revenue / ms.order_count,
| ^~~~~
= help: did you mean 'round'?
Format (docs)
Deterministic formatting with configurable line width, keyword casing, and indentation:
echo "select u.id,u.name, p.title from users u join posts p on u.id=p.user_id
where u.active=1 and p.published=true order by p.created_at desc limit 10" \
| syntaqlite fmt
SELECT u.id, u.name, p.title
FROM users u
JOIN posts p ON u.id = p.user_id
WHERE u.active = 1
AND p.published = true
ORDER BY p.created_at DESC
LIMIT 10;
Version and compile-flag aware (docs)
Pin the parser to a specific SQLite version or enable compile-time flags to match your exact build:
# Reject syntax your target SQLite version doesn't support
syntaqlite --sqlite-version 3.32.0 validate query.sql
# Enable optional syntax from compile-time flags
syntaqlite --sqlite-cflag SQLITE_ENABLE_MATH_FUNCTIONS validate query.sql
Validate SQL inside other languages (experimental)
SQL lives inside Python and TypeScript strings in most real codebases. syntaqlite extracts and validates it, handling interpolation holes: