用于sqla过滤器的yaml解析器。
sqla-filters-yaml的Python项目详细描述
Sqla过滤器yaml
将yaml解析器添加到sqla filters包中。
简介
向sqla过滤器添加yaml支持。
要求
这个包使用python包pyyaml
要安装pyyaml,需要有yaml.h头文件。如果不是的话
在您的系统上,您需要安装libyaml dev包。
- 在软呢帽上
sudo dnf install libyaml-devel
- 基于debian的发行版(ubuntu,…)
sudo apt install libyaml-dev
安装
pip install sqla-filter-yaml
开始
yaml格式
--- 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
:警告:yaml格式将来可能会更改。:警告:
示例代码
从yaml字符串/文档创建yamlitterparser的实例。
示例:
# Sqlalchemy setup + model definition# Create a YAML parser instanceparser=YAMLiltersParser(raw_json_string)# You can finaly filter your queryquery=session.query(Post)filtered_query=parser.tree.filter(query)# Get the resultsquery.all()
结果树
+----------------------+
| |
| and |
| |
-----------------------+
||
||
||
+----------------------+ || +----------------------+
| | || | |
| or <------------> age == 21 |
| | | |
+----------------------+ +----------------------+
||
||
||
+----------------------+ || +----------------------+
| | || | |
| name == toto <----------------> name == tata |
| | | |
+----------------------+ +----------------------+
贡献
派生存储库并运行以下命令以安装依赖项和开发人员依赖项。
pip install -e '.[dev]'