Skip to main content

A CLI in Python that analyzes raw SQL queries for common anti-patterns

Project description

SQLEyes


Tests

About SQLEyes

SQLEyes is a CLI tool for analyzing simple, raw SQL queries for common sql anti-patterns.

Usage

This package can be installed using pip install sqleyes. After installation, open a terminal and type sqleyes -h to open a help guide showing all possible options and arguments.

$ sqleyes -h

usage: sqleyes [-h] -q

Analyze raw SQL queries for anti-patterns

optional arguments:
  -h, --help     show this help message and exit
  -q , --query   A raw SQL query to analyze

To analyze a query use the -q flag with the query in string format.

$ sqleyes -q "SELECT * FROM product WHERE pCategory <> NULL"

[{"type": "Implict Columns", "detector_type": "anti-pattern"},
{"type": "Fear of the Unknown", "detector_type": "anti-pattern"}]

This package can also be imported into existing projects. Make sure it is installed in your project's virtual environment.

from sqleyes.utils.query_functions import check_single_value_rule

# Use a sqleyes function
has_single_values = check_single_value_rule(["AVG(price)"])

...

from sqleyes.main import main

# Check a query for anti-patterns
anti_patterns = main("SELECT * FROM product")

Repository

This repository contains the main SQLEyes package as well as the unit tests

Contributing

  1. Make sure you have all the required packages installed. These can be found in requirements.txt and requirements_dev.txt.
  2. Create a new feature branch git checkout -b feature/<FEATURE NAME>.
  3. Install the package in editable mode using pip install -e ., which installs the package locally. Changes to the package a directly reflected in your environment.
  4. (Optional) In order for the CLI tool to work in editable mode, run pip install . after step 3.
  5. Implement the desired features.
  6. Write unit tests inside the tests directory.
  7. Make sure all unit tests pass by running pytest in the root of the repository.
  8. Make sure linting and static type hinting is proper by running flake8 sqleyes tests and mypy sqleyes.
  9. Create a pull request describing your feature.

Building and distribution

  1. Make sure all tests passed, linting and static type hinting are proper (see steps 7 & 8 of Contribution).
  2. Increase version number accordingly.
  3. Run python -m build in the root directory. A dist folder will be generated.
  4. Upload the package to PyPI using Twine (pip install twine) using the following command: twine upload dist/*.

Acknowledgements

This project was developed as a master's graduation project at Eindhoven University of Technology. Code boilerplate and best practices from best-practice-and-impact. This package depends on some of sqlparse features for parsing SQL queries.

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

sqleyes-0.5.0.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

sqleyes-0.5.0-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file sqleyes-0.5.0.tar.gz.

File metadata

  • Download URL: sqleyes-0.5.0.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for sqleyes-0.5.0.tar.gz
Algorithm Hash digest
SHA256 1b41750f590ecbeb598e54be30fc5de881a80e1b46d47764ca69d06c90b1ed7a
MD5 47335c7616c9a36918bc1f29774793e3
BLAKE2b-256 4d97765fcbee29c526630f6c6a92c45ecc5a6b6c0cfaf2524ac6dc59d589a277

See more details on using hashes here.

File details

Details for the file sqleyes-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: sqleyes-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 24.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for sqleyes-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 abf2845bb3edbc9e09a7d384a4d6019e228f4c70f0703dbf3b62a8607e3d8dac
MD5 8499dd0566f90cf422282c254e92b7e3
BLAKE2b-256 032249472ac6f335485329e74499ebf40f9549679865a418c711df693e200a45

See more details on using hashes here.

Supported by

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