Skip to content

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

License

Notifications You must be signed in to change notification settings

leonardomathon/sqleyes

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages