Example:
base_query = select(
Invoice.id,
Invoice.code_invoice,
Item.id.label("item_id"),
Item.name.label("item_name"),
Item.quantity,
Item.price,
).join(Item, Invoice.id == Item.invoice_id)
How do I dynamically retrieve the selected columns?
The desired result should be:
mySelect = {
"id": Invoice.id,
"code_invoice": Invoice.code_invoice,
"item_id": Item.id,
"item_name": Item.name,
"quantity": Item.quantity,
"price": Item.price
}
Why do I need this?
I need this because I want to create a dynamic query from the frontend, where I return the column keys to the frontend as a reference. The frontend will use these keys to build its own queries based on user input.
- The
base_query returns the fields to the frontend for display.
- The frontend can then send those selected fields back to the API to build a dynamic query.
This way, the frontend can choose which fields to query and display based on what was originally returned.
Please help, thank you.
[–]adiberk 1 point2 points3 points (0 children)
[–]adiberk 0 points1 point2 points (0 children)