PySquel
POC for linting SQL statements in Python.
Relying on sqlfluff.
The name is inspired by Czech word paskvil which means messed up.
Concept
Using str subclass called sql to mark all SQL statements for linting.
It causes avoidance of parsing the SQL statements from all strings.
from pysquel import sql
my_sql = sql("SELECT * FROM table")
# `sql` is a just subclass of the str
>>> type(my_sql)
<class 'str'>
>>> sql("SELECT * FROM {table}").format(table="super_table")
'SELECT * FROM super_table'
It could be better in the future:
- tagstr
sql"SELECT FROM table" sql_f"SELECT FROM {table}"
- dedent
sql_d""" SELECT FROM table """ sql_df""" SELECT FROM {table} """
Usage
# tests/test_lint.py
from pysquel import sql
bad_sql = sql(
"""
SELECT *
FROM
table
""")
Run pysquel . to lint all sql statements in the current directory:
tests/test_lint.py :
--------------------------------------------------------------------------------
SELECT *
FROM
table
--------------------------------------------------------------------------------
{'line_no': 1, 'line_pos': 1, 'code': 'LT01', 'description': "Expected only single space before 'SELECT' keyword. Found ' '.", 'name': 'layout.spacing'}
{'line_no': 1, 'line_pos': 1, 'code': 'LT02', 'description': 'First line should not be indented.', 'name': 'layout.indent'}
{'line_no': 1, 'line_pos': 1, 'code': 'LT13', 'description': 'Files must not begin with newlines or whitespace.', 'name': 'layout.start_of_file'}
{'line_no': 1, 'line_pos': 3, 'code': 'AM04', 'description': 'Query produces an unknown number of result columns.', 'name': 'ambiguous.column_count'}
{'line_no': 1, 'line_pos': 11, 'code': 'LT01', 'description': 'Unnecessary trailing whitespace.', 'name': 'layout.spacing'}
{'line_no': 2, 'line_pos': 5, 'code': 'LT01', 'description': 'Unnecessary trailing whitespace.', 'name': 'layout.spacing'}
{'line_no': 3, 'line_pos': 1, 'code': 'LT02', 'description': 'Expected indent of 4 spaces.', 'name': 'layout.indent'}
================================================================================
TODO
- config
- exclude rules
- exclude dirs
- noqa
sqlfluffconfig (dialect, templating, ...)- custom token instead of
sql? - lint missing
sqlprefix for potential SQL statements
Metadata
Release files for pysquel 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pysquel-0.0.1.tar.gz | 3.0 kB | Without provenance | Details for pysquel-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pysquel-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for pysquel-0.0.1-py3-none-any.whl |
Total release size: 6.9 kB
Release files / pysquel-0.0.1.tar.gz
| Download URL | pysquel-0.0.1.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
86e00cb5f5fca51a4e5b39127fb8d690792297787565dd5e5ab3a93c65508289
|
|
BLAKE2b-256 checksum How to use checksums |
53348a2a1a84e7f6c124e8adb4a1fb7a2585fd53629f703f8cdaea03c11312ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.0 CPython/3.11.6 Linux/6.5.0-10-generic
|
Release files / pysquel-0.0.1-py3-none-any.whl
| Download URL | pysquel-0.0.1-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0154811770f18617b118865abd5bf6be4693e2d85a7c62ce27512b08249d8c81
|
|
BLAKE2b-256 checksum How to use checksums |
8b98b9302210834ad89bd09a6c7702470a14e9e8a85dd356ff84e0d86dff1178
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.0 CPython/3.11.6 Linux/6.5.0-10-generic
|
Security for pysquel 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.