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
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
Hashes for sql_to_pypika-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23155ca0144368667c042435f0f08f88300236f178879c32f3c75023bd0e82b5 |
|
MD5 | 0850767919b2cf08ac3a29f0dbb6c50b |
|
BLAKE2b-256 | 8f762942c826b8239c25cd2e5ab71921a7e7626034d6bc5b04417a18cd700b58 |