updated Query options
This commit is contained in:
@@ -1,18 +1,26 @@
|
||||
from Schemas import AddressNeighborhood
|
||||
from typing import Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
from Services.PostgresDb.Models.crud_alchemy import Credentials
|
||||
from Services.PostgresDb.Models.mixin import BasicMixin
|
||||
from Services.PostgresDb.Models.pagination import Pagination, PaginationResult
|
||||
from Services.PostgresDb.Models.pagination import Pagination, PaginationResult, QueryOptions
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
listing = False
|
||||
listing = True
|
||||
creating = False
|
||||
updating = True
|
||||
updating = False
|
||||
|
||||
new_session = AddressNeighborhood.new_session()
|
||||
new_session_test = AddressNeighborhood.new_session()
|
||||
|
||||
BasicMixin.creds = Credentials(person_id=10, person_name="Berkay Super User")
|
||||
|
||||
class QueryModel(BaseModel):
|
||||
neighborhood_name: Optional[str]
|
||||
neighborhood_code: Optional[str]
|
||||
|
||||
|
||||
if listing:
|
||||
"""List Options and Queries"""
|
||||
@@ -20,25 +28,36 @@ if listing:
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=new_session,
|
||||
).query
|
||||
query_of_list_options = {
|
||||
"neighborhood_name__ilike": "A%",
|
||||
"neighborhood_code__contains": "3",
|
||||
}
|
||||
address_neighborhoods = AddressNeighborhood.filter_all(
|
||||
*AddressNeighborhood.convert(query_of_list_options),
|
||||
db=new_session,
|
||||
)
|
||||
pagination = Pagination(data=address_neighborhoods)
|
||||
pagination.page = 9
|
||||
pagination.size = 10
|
||||
pagination.orderField = ["type_code", "neighborhood_code"]
|
||||
pagination.orderType = ["desc", "asc"]
|
||||
|
||||
pagination_result = PaginationResult(
|
||||
data=address_neighborhoods, pagination=pagination
|
||||
)
|
||||
print(pagination_result.pagination.as_dict())
|
||||
print(pagination_result.data)
|
||||
list_options = {
|
||||
"page": 1,
|
||||
"size": 11,
|
||||
"order_field": ["type_code", "neighborhood_code"],
|
||||
"order_type": ["asc", "desc"],
|
||||
"query": {
|
||||
"neighborhood_name__ilike": "A%",
|
||||
"neighborhood_code__contains": "3",
|
||||
"my_other_field__ilike": "B%",
|
||||
"other_other_field__ilike": "C%",
|
||||
}
|
||||
}
|
||||
|
||||
query_options = QueryOptions(table=AddressNeighborhood, data=list_options, model_query=QueryModel)
|
||||
address_neighborhoods = AddressNeighborhood.filter_all(*query_options.convert(), db=new_session)
|
||||
|
||||
pagination = Pagination(data=address_neighborhoods)
|
||||
pagination.change(**list_options)
|
||||
|
||||
pagination_result = PaginationResult(data=address_neighborhoods, pagination=pagination)
|
||||
print("as_dict", pagination_result.pagination.as_dict())
|
||||
for i, row in enumerate(pagination_result.data):
|
||||
print(i+1, row)
|
||||
|
||||
# list_options_valid = ListOptions(**list_options)
|
||||
# pagination.page = 9
|
||||
# pagination.size = 10
|
||||
# pagination.orderField = ["type_code", "neighborhood_code"]
|
||||
# pagination.orderType = ["asc", "asc"]
|
||||
|
||||
if creating:
|
||||
"""Create Queries"""
|
||||
@@ -62,9 +81,7 @@ if creating:
|
||||
if updating:
|
||||
"""Update Queries"""
|
||||
|
||||
query_of_list_options = {
|
||||
"uu_id": str("33a89767-d2dc-4531-8f66-7b650e22a8a7"),
|
||||
}
|
||||
query_of_list_options = {"uu_id": str("33a89767-d2dc-4531-8f66-7b650e22a8a7")}
|
||||
print("query_of_list_options", query_of_list_options)
|
||||
address_neighborhoods_one = AddressNeighborhood.filter_one(
|
||||
*AddressNeighborhood.convert(query_of_list_options),
|
||||
|
||||
Reference in New Issue
Block a user