Sqleibniz
Static analysis and LSP for SQL in Rust
Install / Use
/learn @xnacly/SqleibnizREADME
sqleibniz
Static analysis and LSP for SQL in Rust. Check for valid syntax, semantics and perform dynamic analysis.
[!WARNING]
Sqleibniz is in early stages of development, please keep this in mind before creating issues. Contributions are always welcome 💗
Features
Sqleibniz is a command line tool to analyse sql statements by checking for their static and dynamic correctness. See below for a list of currently implemented features.
Supported features
- [ ] static analysis (syntax and semantic analysis)
- [x] syntax analysis - sqleibniz aims to implement the syntax sqlite understands
- [ ] warn for sqlites quirks
- [ ] do the used tables exist / were they created beforehand
- [ ] do the used columns exist / were they created beforehand
- [ ] do the used functions exist / were they created beforehand
- [ ] are all used types compatible
- [ ] dynamic analysis (runtime analysis via embedded sqlite)
- [ ] assertions via
@sqleibniz::assert - [ ] were all tables and their columns created correctly (with correct storage classes)
- [ ] were all stmts executed successfully
- [ ] assertions via
- [ ] pretty errors
- [x] faulty code display with line numbers
- [x] link to sqlite documentation for each diagnostic
- [x] ability to omit specific errors depending on their group (Rule)
- [x] highlighting the error in the faulty code snippet
- [x] explanation why the specific error was ommitted based on its Rule
- [x] syntax highlighting in terminal errors
- [ ] possible fix suggestions
- [x] suggestions for unknown and possible misspelled keywords
- [ ] language server protocol
- [x] diagnostics for full sqleibniz analysis
- [ ] snippets
- [ ] intelligent completions
- [ ] lua scripting
- [x] configure sqleibniz with lua
- [x] scripting to hook into node analysis for custom diagnostics
- [ ] execute hooks when encountering the defined node while analysing
Supported Sql statements
| sqlite specification | syntax analysis | semantic analysis | Example |
| -------------------------------------------------------------------------- | --------------- | ----------------- | --------------------------------------------------------- |
| explain-stmt | ✅ | ❌ | EXPLAIN QUERY PLAN; |
| alter-table-stmt | ✅ | ❌ | ALTER TABLE schema.table_name ADD new_column_name TEXT; |
| analyze-stmt | ✅ | ❌ | ANALYZE my_table; |
| attach-stmt | ✅ | ❌ | ATTACH DATABASE 'users.db' AS users; |
| begin-stmt | ✅ | ❌ | BEGIN DEFERRED TRANSACTION; |
| commit-stmt | ✅ | ❌ | END TRANSACTION; |
| create-index-stmt | ❌ | ❌ | |
| create-table-stmt | ❌ | ❌ | |
| create-trigger-stmt | ❌ | ❌ | |
| create-view-stmt | ❌ | ❌ | |
| create-virtual-table-stmt | ❌ | ❌ | |
| delete-stmt | ❌ | ❌ | |
| detach-stmt | ✅ | ❌ | DETACH DATABASE my_database |
| drop-index-stmt | ✅ | ❌ | DROP INDEX my_index; |
| drop-table-stmt | ✅ | ❌ | DROP TABLE my_table; |
| drop-trigger-stmt | ✅ | ❌ | DROP TRIGGER my_trigger; |
| drop-view-stmt | ✅ | ❌ | DROP VIEW my_view; |
| insert-stmt | ❌ | ❌ | |
| pragma-stmt | ✅ | ❌ | PRAGMA schema.optimize(0xfffe); |
| reindex-stmt | ✅ | ❌ | REINDEX my_schema.my_table |
| release-stmt | ✅ | ❌ | RELEASE SAVEPOINT latest_savepoint |
| rollback-stmt | ✅ | ❌ | ROLLBACK TO latest_savepoint; |
| savepoint-stmt | ✅ | ❌ | SAVEPOINT latest_savepoint |
| select-stmt | ❌ | ❌ | |
| update-stmt | ❌ | ❌ | |
| vacuum-stmt | ✅ | ❌ | VACUUM INTO 'repacked.db' |
Installation
cargo
cargo install --git https://github.com/xnacly/sqleibniz
from source
git clone https://github.com/xnacly/sqleibniz
cargo install --path .
via make
this builds the project with cargo and moves the resulting binary to
/usr/bin/.
git clone https://github.com/xnacly/sqleibniz
make
Uninstall via:
make uninstall
Command line interface usage
Static analysis and LSP for SQL in Rust
Usage: sqleibniz [OPTIONS] [PATHS]...
Arguments:
[PATHS]...
files to analyse
Options:
-i, --ignore-config
instruct sqleibniz to ignore the configuration, if specified
-c, --config <CONFIG>
path to the configuration
[default: leibniz.lua]
-s, --silent
disable stdout/stderr output
-D <DISABLE>
disable diagnostics by their rules, all are enabled by default - this may change in the future
Possible values:
- no-content: Source file is empty
- no-statements: Source file is not empty but holds no statements
- unimplemented: Source file contains constructs sqleibniz does not yet understand
- unknown-keyword: Source file contains an unknown keyword
- bad-sqleibniz-instruction: Source file contains invalid sqleibniz instruction
- sqlite-unsupported: Source file uses sql features sqlite does not support
- quirk: Sqlite or SQL quirk: https://www.sqlite.org/quirks.html
- unterminated-string: Source file contains an unterminated string
- unknown-character: The source file contains an unknown character
- invalid-numeric-literal: The source file contains an invalid numeric literal, either overflow or incorrect syntax
- invalid-blob: The source file contains an invalid blob literal, either bad hex data (a-f,A-F,0-9) or incorrect syntax
- syntax: The source file contains a structure with incorrect syntax
- semicolon: The source file is missing a semicolon
--ast-json
dump the abstract syntax tree as pretty printed json
--ast
dump the abstract syntax tree as rusts pretty printed debugging
--lsp
invoke sqleibniz as a language server
-h, --help
Print help (see a summary with '-h')
-V, --version
Print versio
Configuration
Sqleibniz can be configured via a leibniz.lua file, this file has to be
accessible to sqleibniz by existing at the path sqleibniz is invoked at.
Consult src/rules.rs for configuration documentation and
leibniz.lua for said example:
-- this is an example configuration, consult: https://www.lua.org/manual/5.4/
-- or https://learnxinyminutes.com/docs/lua/ for syntax help and
-- src/rules.rs::Config for all available options
leibniz = {
disabled_rules = {
