Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom query expression #87

Merged
merged 5 commits into from
Nov 20, 2022
Merged

Custom query expression #87

merged 5 commits into from
Nov 20, 2022

Conversation

kbarbounakis
Copy link
Contributor

@kbarbounakis kbarbounakis commented Nov 20, 2022

This MR adds a new feature for defining custom query expressions for readonly fields. This operation allows parsing custom query expressions and include them in data model's view adapter.
e.g. A business process needs customer's email address customer.email to be an attribute of an Order even if it would be retrieved by expanding customer.

Define a readonly attribute orderEmail

{
    "name": "orderEmail",
    "readonly": true,
    "type": "Text",
    "nullable": true,
    "query": [
        {
            "$lookup": {
                "from": "Person",
                "foreignField": "id",
                "localField": "customer",
                "as": "customer"
            }
        },
        {
            "$project": {
                "orderEmail": "$customer.email"
            }
        }
    ]
}

where orderEmail has a custom query with two stages:

  1. Join Person collection based on customer attribute of an order.
{
    "$lookup": {
        "from": "Person",
        "foreignField": "id",
        "localField": "customer",
        "as": "customer"
    }
}
  1. Select customer.email as part of an order
{
    "$project": {
         "orderEmail": "$customer.email"
     }
}

The result will be a new extra field based on an SQL statement equivalent to the following one:

CREATE VIEW OrderData AS SELECT ..., OrderBase.customer , customer.email AS orderEmail 
     LEFT JOIN PersonData AS customer ON OrderBase.customer = customer.id

@kbarbounakis kbarbounakis merged commit 8c7b76a into master Nov 20, 2022
@kbarbounakis kbarbounakis deleted the 75-custom-query-expr branch November 20, 2022 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant