Skip to main content

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.

Files for sqlint, version 0.2.4
Filename, size File type Python version Upload date Hashes
Filename, size sqlint-0.2.4-py3-none-any.whl (28.0 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size sqlint-0.2.4.tar.gz (22.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page