Capture and analyze SQL queries made during a run your app's test suite
Project description
sql-critic
Capture and analyze SQL queries made during a run of your app's test suite.
Receive feedback about dubious queries in a PR comment.
How it works
Phase 1: Query collection
This phase hooks into your test suite and records any database queries captured by OpenTelementry instrumentation.
NOTE: This step only has Python language support at the moment! However, it's a simple wrapper around OpenTelemetry which could be ported to any other language in theory.
Example using pytest
:
from sqlcritic.collector import Collector
collector = Collector()
def pytest_sessionstart(session):
# only necessary if your app is not already instrumented
# SQLite here is just an example - there is auto instrumentation for lots
# of different database adapters
from opentelemetry.instrumentation.sqlite3 import SQLite3Instrumentor
SQLite3Instrumentor().instrument()
def pytest_runtest_call(item):
path, line, name = item.reportinfo()
with collector.trace_test(path, line, name):
item.runtest()
def pytest_sessionfinish(session, exitstatus):
collector.save_results("results.json")
Phase 2: Analysis
The analysis of queries collected during your test suite happens in a GitHub action. Make sure to run this step after your test suite has run and outputted the queries results (i.e. in results.json
for example).
- uses: scttnlsn/sql-critic@main
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
data-path: "results.json"
The results will be posted as a PR comment in the repo utilizing this action.
Development
Setup
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e ".[dev]"
Testing
python -m pytest
Dependencies
When dependencies are updated in pyproject.toml
then we need to regenerate requirements.txt
(which is used for the GitHub action):
pip-compile -o requirements.txt pyproject.toml
Releasing
pip install build twine
python -m build
twine check dist/*
twine upload dist/*
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
Built Distribution
File details
Details for the file sqlcritic-0.2.0.tar.gz
.
File metadata
- Download URL: sqlcritic-0.2.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7546521b5ef27b1de0c20ba17e81e16b70304d339a62e6ae42863234531ff3d5 |
|
MD5 | 00054ad7355463f1ac9d87ce0f447a5b |
|
BLAKE2b-256 | c0480ea2c32fafd146702d4b0fe40375a743bdbe81beb96283bd8cfc3cde03f0 |
File details
Details for the file sqlcritic-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: sqlcritic-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a486117ed02a9ba63f9fa430ef6f5a0140841fe2aac993b4535d67e6a2e0c945 |
|
MD5 | d7f9d125970b317ed652f133baa205ed |
|
BLAKE2b-256 | c416d6aa3650c95d792d42482c742224c502716dca901fa591ee02fa1d371d51 |