app.utils.request_query_operator
Description
Module for creating a Peewee filter query via dynamic way.
Next module is used for creating a Peewee query based on request fields.
References
Query operators http://docs.peewee-orm.com/en/latest/peewee/query_operators.html
Classes
|
|
- class app.utils.request_query_operator.Helper
- build_clause_operators(field: peewee.Field, field_operator: str, field_value) tuple
- static build_order_by(db_model: Type[peewee.Model], request_data: dict) list
Build sorting fields with zero or more Column-like objects to order by.
Example
Peewee query: User.select().order_by(User.created_at.asc())
Request fields: >>> from app.models.user import User >>> db_model = User >>> request_data = {‘order’: [{‘sorting’: ‘asc’, ‘field_name’: ‘created_at’}]} >>> Helper.build_order_by(db_model, request_data) [<peewee.Ordering object at …>]
Notes
Actually is not posible to order across joins.
References
http://docs.peewee-orm.com/en/latest/peewee/querying.html#sorting-records http://docs.peewee-orm.com/en/latest/peewee/api.html#Query.order_by
- build_sql_expression(field: peewee.Field, field_operator: str, field_value)
- build_string_clause(field: peewee.Field, field_operator: str, field_value) tuple
Build string clauses.
You can find next string operators: +————+—————————————–+ | Name | Description | +============+=========================================+ | eq | x equals y | +————+—————————————–+ | ne | x is not equal to y | +————+—————————————–+ | contains | Wild-card search for substring | +————+—————————————–+ | ncontains | Wild-card not search for substring | +————+—————————————–+ | startswith | Search for values beginning with prefix | +————+—————————————–+ | endswith | Search for values ending with suffix | +————+—————————————–+
Example
TODO: Pending to define