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

Query virtual attributes #17

Open
Speedy37 opened this issue Nov 9, 2017 · 0 comments
Open

Query virtual attributes #17

Speedy37 opened this issue Nov 9, 2017 · 0 comments

Comments

@Speedy37
Copy link
Contributor

Speedy37 commented Nov 9, 2017

Goal: being able to answer to:

  • give me all persons with a least 3 cats
  • give me the latest version of a document for each distinct document theme
  • give the number of cats each persons possess and order them by that number.

Solution: virtual attributes

A virtual attribute is a specially named attribute that represent a computed value and can be used as any other attribute in query (for both conditions and scope)

A virtual attribute can only return a single value.

The $count virtual attribute

Gives the number of values hold by an attribute. If the attribute is sigle value, gives 1 if the value exists, 0 otherwise.

Syntax: $count(attribute)

The range selection virtual attribute

For a set of objets, objects are grouped by a set of attributes then for each group ordered inside it.

Syntax:

  • $isLast(attribute ordering) / group by attribute: true if it's the last value in the ordered set of objects optionally grouped by a set of attributes
  • $isFirst(attribute ordering) / group by attribute: true if it's the first value in the ordered set of objects optionally grouped by a set of attributes

Examples:

  • { $instanceOf: "Person", "$count(_cats)": { $gte: 3 } }
  • { $instanceOf: "Document", "$isLast(+_date) / _theme": true }
  • { scope: ["+$count(_cats)"] }
Speedy37 pushed a commit that referenced this issue Nov 20, 2017
 - this is a massive commit, that will have an impact on #19, #16, #17, #8 and #20
 - a ton of tests will be added very soon as this new implementation is much prone to state errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant