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

Support access to attribute name to use it as value in projections #20

Open
Vitalhead opened this issue Feb 28, 2020 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@Vitalhead
Copy link

There are many cases when you need to convert an attribute name into values. What ma help is to have a keys() function that returns an array of keys.

Use Case 1:
Objects described in Json where ID of the object is the key need to be converted into an array of objects where ID is the property.
For example:
{
“a”: {"prop": "value1"},
“b”: {"prop": "value2"}
}
Convert to:
[
{“_id”: “a”, "prop": "value1"},
{“_id”: “b”, "prop": "value2"}
]

Use Case 2:
Key-value pairs need to be expanded to objects. And it should work for the arbitrary number of attributes.
For example:
{
“name”: "Milk",
“price”: 1
}
Convert to:
[
{“prop”: “name”, "value": "Milk"},
{“prop”: “price”, "value": 1}
]

@judofyr
Copy link
Contributor

judofyr commented Feb 29, 2020

Just brainstorming some ideas here:

What about a function called entries(…) which turns an object{"a": "c"} into [{"key": "a", "value": "c"}? Your two examples would then be entries(foo) | { "_id": key, ...value } and entries(foo) | { "prop": key, value }.

@Vitalhead
Copy link
Author

entries() function may work. How it will behave on array?

Also, need to think if it will help in the following use case:
[ [col1, col2], [val11, val12], [val21, val22] ]
to convert to:
[ {col1: val11, col2: val12}, {col1: val11, col2: val12}, ]

@judofyr judofyr added the enhancement New feature or request label Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants