atviriduomenys / spinta

Spinta is a framework to describe, extract and publish data (a DEP Framework).
MIT License
10 stars 4 forks source link

Add possibility to use text type as page key #583

Open sirex opened 3 months ago

sirex commented 3 months ago

Add possibility to use string part of text type as a page key. For example:

d | r | b | m | property | type   | ref     | level | access
datasts/example          |        |         |       |
  | resource1            | sql    |         |       |
  |   |   | Country      |        | name@en | 4     |
  |   |   |   | name@en  | string |         | 4     | open
  |   |   | City         |        | name@en | 4     |
  |   |   |   | name@en  | string |         | 4     | open
  |   |   |   | country  | ref    | Country | 3     | open

User should be able to do:

http get /datasets/example/Country

In this query, pagination will be done using name@en as page key, for external backends, and this internally should result in fallowing data:

{
    "_data": [
        {
            "_type": "datasts/example/City",
            "_id": "dcfae257-962d-4204-b483-b03836addf7d",
            "name": {
                "en": "Vilnius"
            },
            "country": {
                "name": {
                    "en": "Lithuania"
                }
            }
        }
    ],
    "_page": {
        "next": "base64(['Lithuania'])"
    }
}

In order to calculate next page value, we need to order by and select name@en. Basically this should result into something like this:

select(_page: [name@en], *)

We need to separate page key, from other selected columns. If we expand *, we get:

select(_page: [name@en], name, country)

And the data would look like:

{
    "_page": [
        "Vilnius",     # string value of name@en
    ],
    "name": "Vilnius", # implicit form of text type
    "country": {
        "name": {
            "en": "Lithuania"  # explicit form of text
        }
    }
}

Related