Simple Sql Linter
Project description
This is a SQL parser and linter for Standard SQL(BigQuery).
https://github.com/shigeru0215/sqlint
Install
$ pip install sqlint
Usage
linting
$ cat example.sql
>> select
>> a + b as x
>> , b+c as y
>> from
>> test_table as t1
$ sqlint example.sql
>> example.sql (L3, 8): whitespace must be before binary operator: b+
>> example.sql (L3, 8): whitespace must be after binary operator: +c
formatting
With -f option, this linter show formatted SQL.
$ sqlint -f query/example.sql
>> select
>> a + b as x
>> , b + c as y
>> from
>> test_table as t1
REPL
$ python
>>> from sqlint import parse, check, format
>>> sql = 'SELECT id From user_table where user_table.age >10'
>>>
>>> parse(sql)
[[<Keyword: 'SELECT'>, <Whitespace: ' '>, <Identifier: 'id'>, <Whitespace: ' '>, <Keyword: 'From'>, <Whitespace: ' '>, <Identifier: 'user_table'>, <Whitespace: ' '>, <Keyword: 'where'>, <Whitespace: ' '>, <Identifier: 'user_table.age'>, <Whitespace: ' '>, <Operator: '>'>, <Identifier: '10'>]]
>>>
>>> check(sql)
['(L1, 1): reserved keywords must be lower case: SELECT -> select', '(L1, 11): reserved keywords must be lower case: From -> from', '(L1, 26): too many spaces', '(L1, 49): whitespace must be after binary operator: >10']
>>>
>>> format(sql)
>>> select
>>> id
>>> from
>>> user_table
>>> where
>>> user_table.age > 10
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sqlint-0.2.4.tar.gz
(22.4 kB
view details)
Built Distribution
sqlint-0.2.4-py3-none-any.whl
(28.0 kB
view details)
File details
Details for the file sqlint-0.2.4.tar.gz
.
File metadata
- Download URL: sqlint-0.2.4.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ca49c335d8f3fdc00d01496760b7e0a2a830c7dec789673f1c771f9e7086020 |
|
MD5 | cdd5ecf8dd0e4700c237f889ce0598a9 |
|
BLAKE2b-256 | 4e01753afcac22292caa6d2eb71e7b2fe7cf5e2da9ed760f7f9634790ec2c9c9 |
File details
Details for the file sqlint-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: sqlint-0.2.4-py3-none-any.whl
- Upload date:
- Size: 28.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0ef21658a2003bfce2dc63354d46c1057e516f2b5f5e0191774b261e8f45fd5 |
|
MD5 | d8f43bffa4bde6f71aa3a28f17912989 |
|
BLAKE2b-256 | ee6c482bae9a62c4fd45788b4134e8fdc8f3fdf6a93c245c528df77b69e45bed |