Skip to main content

No project description provided

Project description

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
  • sqlfluff config (dialect, templating, ...)
  • custom token instead of sql?
  • lint missing sql prefix for potential SQL statements

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

pysquel-0.0.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysquel-0.0.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file pysquel-0.0.1.tar.gz.

File metadata

  • Download URL: pysquel-0.0.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.11.6 Linux/6.5.0-10-generic

File hashes

Hashes for pysquel-0.0.1.tar.gz
Algorithm Hash digest
SHA256 86e00cb5f5fca51a4e5b39127fb8d690792297787565dd5e5ab3a93c65508289
MD5 0af24533bc7b7c0e0157408140ba8f00
BLAKE2b-256 53348a2a1a84e7f6c124e8adb4a1fb7a2585fd53629f703f8cdaea03c11312ac

See more details on using hashes here.

File details

Details for the file pysquel-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pysquel-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.11.6 Linux/6.5.0-10-generic

File hashes

Hashes for pysquel-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0154811770f18617b118865abd5bf6be4693e2d85a7c62ce27512b08249d8c81
MD5 f4cc3f72f537758cbbfb308081adfcac
BLAKE2b-256 8b98b9302210834ad89bd09a6c7702470a14e9e8a85dd356ff84e0d86dff1178

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page