JSON parser for sqla-filters.
Project description
Sqla-filters-json
Add json parser to the sqla-filters package.
Introduction
This package
Installation
pip install sqla-filter-json
Getting Started
JSON format
{
"type": "and",
"data": [
{
"type": "or",
"data": [
{
"type": "operator",
"data": {
"attribute": "name",
"operator": "eq",
"value": "toto"
}
},
{
"type": "operator",
"data":{
"attribute": "name",
"operator": "eq",
"value": "tata"
}
}
]
},
{
"type": "operator",
"data": {
"attribute": "age",
"operator": "eq",
"value": 21
}
}
]
}
:warning: Json format can change in the futur. :warning:
Create an instance of the JSONFilterParser with the json string.
Example:
# Sqlalchemy setup ... + model definition
# Create a JSON parser instance
parser = JSONFiltersParser(raw_json_string)
# you now have a tree available as a property in the parser
print(parser.tree)
# You can finaly filter your query
query = session.query(Post)
filtered_query = parser.tree.filter(query)
# Get the results
query.all()
Result tree
+----------------------+
| |
| and |
| |
-----------------------+
||
||
||
+----------------------+ || +----------------------+
| | || | |
| or <------------> age == 21 |
| | | |
+----------------------+ +----------------------+
||
||
||
+----------------------+ || +----------------------+
| | || | |
| name == toto <----------------> name == tata |
| | | |
+----------------------+ +----------------------+
Contribute
Fork the repository and run the following command to install the dependencies and the dev dependencies.
pip install -e '.[dev]'
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
Close
Hashes for sqla_filters_json-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f463fa0f5044ada29a811d55c5d10687824e6c1e5dddbfc11de02d6f0cf617a |
|
MD5 | a64ca17d8c32ae863dbf2b5fa6eba00f |
|
BLAKE2b-256 | 0237e83e5430d01c511c332d42d0b638e1da2cecf1e0bc7ed8855dae477321fc |