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

Add possibility to use text type as ref key #582

Closed
sirex opened this issue Mar 18, 2024 · 1 comment · May be fixed by #584
Closed

Add possibility to use text type as ref key #582

sirex opened this issue Mar 18, 2024 · 1 comment · May be fixed by #584

Comments

@sirex
Copy link
Collaborator

sirex commented Mar 18, 2024

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

Here we use name@en as primary key and as an external key, with level set to 3, that means, we have to use original column values instead of _id.

In this case data for writing and reading of City model should look like this:

{
    "_type": "datasts/example/City",
    "_id": "dcfae257-962d-4204-b483-b03836addf7d",
    "name": {
        "en": "Vilnius"
    },
    "country": {
        "name": {
            "en": "Lithuania"
        }
    }
}

For mapping name@en with _id, via keymap, we have to use "Lithuania" value, not {"en": "Lithuania"}.

For storing data in internal PostgreSQL backend, we should store reference data in country.name@en column of string type, because reference is using string part of text type, not the text type itself, bet a part of it.

There should be a distinction made, that text type is a complex type, while string type is a simple type and can go independently or as part of text type.

For data formats, that support complex types, we use a native format form, for example, if we refer to name@en in JSON we should encode it as {"name": {"en": "Lithuania"}}.

If format does not support complex type, like tabular formats, we use "name@en" as column name.

There might be a slight confusion with implicit and explicit forms of text type. Even if text type is a complex type, it can be expressed in two ways:

  • explicit form - {"en": "Lithuania"}
  • implicit form - "Lithuania", where language tag is selected using content negotiation

Related

@sirex
Copy link
Collaborator Author

sirex commented Dec 16, 2024

Create new issue and move #584 to it, or close #584 pull request, if it is not longer relevand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants