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
File details
Details for the file sqla-filters-json-0.0.1.tar.gz
.
File metadata
- Download URL: sqla-filters-json-0.0.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77bd2ba08e53b9c2960744a1665f48c7174313ac164dea2538241d739532834e |
|
MD5 | ae458a09b61003e63b9abfa4a2de140d |
|
BLAKE2b-256 | 2dfb3ecf01ce086551c59ce0975b57d5bd08fada267229b30d3cac887b1b13dc |
File details
Details for the file sqla_filters_json-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: sqla_filters_json-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f463fa0f5044ada29a811d55c5d10687824e6c1e5dddbfc11de02d6f0cf617a |
|
MD5 | a64ca17d8c32ae863dbf2b5fa6eba00f |
|
BLAKE2b-256 | 0237e83e5430d01c511c332d42d0b638e1da2cecf1e0bc7ed8855dae477321fc |