Skip to main content

SQL queries formatting (and soon basic schema less validation)

Project description

sqlvalidator

SQL queries formatting (and soon basic schema less validation)

Formatting

Formatting can be used in 2 ways:

  • formatting Python files that contain SQL strings tagged with # sqlformat from the command line:

sqlvalidator --format myfile.py or sqlvalidator --format myproject/

  • formatting Python strings that represent SQL:

sqlvalidator.format_sql("SELECT * FROM table")

Both output the same formatted string for the same input SQL.

One can verify that all files are correctly formatted using sqlvalidator --check-format pyfile.py

Which won't write the file back and just return a status code. Status code 0 means nothing would change. Status code 1 means some files would reformatted.

Validation

To be implemented yet, but should become the main added-value of this lib.

Suggested API:

import sqlvalidator

sql_query = sqlvalidator.parse("SELECT * from table")

if not sql_query.is_valid():
    print(sql_query.errors)

Ideally, this package should provide a basic SQL validation:

  • not using a missing column
  • existing functions
  • correct aggregations
  • schema-less (not assume that table names and columns in those exist)
  • types correctness in functions

(only on SELECT-statements)

More advanced features:

  • depending on the backend (standard SQL, postgresql, BigQuery, Legacy BigQuery...)
  • Flexible internal SQL representation to do advanced validation
  • With provided schema (to validate that columns exist)

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

sqlvalidator-0.0.2.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

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

sqlvalidator-0.0.2-py2.py3-none-any.whl (25.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sqlvalidator-0.0.2.tar.gz.

File metadata

  • Download URL: sqlvalidator-0.0.2.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7

File hashes

Hashes for sqlvalidator-0.0.2.tar.gz
Algorithm Hash digest
SHA256 0ddb9fee1c7ae6430580bc18868536572c42f2e43d9c7e668315b4b76af48b5e
MD5 e453301f64d2d14d5b667c85e96e6016
BLAKE2b-256 da76d7d6208d7618de20d0d3d31a7fa31e954b32be4475868201a4be19908930

See more details on using hashes here.

File details

Details for the file sqlvalidator-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: sqlvalidator-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7

File hashes

Hashes for sqlvalidator-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bee1e9f2a0a48150cb169085611b2c55835c397962ece7af0abd575948c74081
MD5 738b51191d74bd0cba09d6e8e3863e2c
BLAKE2b-256 75635d2c9dd793189439a3ae08fbafafc1c588c9642993b7e7fd2ade7e141376

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