Convert raw SQL to Pypika Objects
Project description
sql_to_pypika
Helper util for converting raq SQL expressions to PyPika objects. This is neither comprehensive nor perfect. My hope with creating a repo for this is that if people are interested then we can expand on this from here.
Usage
Testing:
> poetry run python -m sql_to_pypika.cli eval --tables="[('foo', 'f')]" --sql="fizz=1"
"f"."fizz"=1
Usage:
tables = [("foo", "foo"), ("bar", "b")]
evaluator = ExpressionEvaluator(tables)
result = evaluator.eval("foo.fizz = 1")
print(result) # "foo"."fizz"=1'
type(result) # pypika.terms.BasicCriterion
result = evaluator.eval("bar.fizz = 1")
print(result) # "b"."fizz"=1'
type(result) # pypika.terms.BasicCriterion
Disclaimer
The logic was initially created by @twheys, the creator of PyPika (gist) via this conversation.
I went ahead and cleaned it up and added some tests so I could use it for my own needs.
Dev / CI
This repo utilize Poetry, for package management. I recommend reading the Poetry install instructions here.
You can then simply run:
poetry install
We use pytest
and Black
for testing and linting respectively. You can use the scripts in the scripts folder to run them.
Project details
Release history Release notifications | RSS feed
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 sql_to_pypika-0.1.0.tar.gz
.
File metadata
- Download URL: sql_to_pypika-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.8.8 Darwin/20.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8cbbe4401a39de4a08aea9e63bd650d9deb874bf51ecc97139f81c7cc0b0efe |
|
MD5 | 1ad7efb3e8decda0993a958da61ed09d |
|
BLAKE2b-256 | d9b017c46a798f00e2f8b3e5120a37bbc7da4c90210640a2385937307203ffb8 |
File details
Details for the file sql_to_pypika-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: sql_to_pypika-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.8.8 Darwin/20.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d51ebbb94d197d5c32b9edb496315fe500c005d22056fb9507eb981a7643557c |
|
MD5 | c026a128c94366542f44f14337247819 |
|
BLAKE2b-256 | e4454428554b551ade6a81c9912eca7a683b704f0e40f3369de34d32bf6f0b0d |