-
Notifications
You must be signed in to change notification settings - Fork 65
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
RFC: Simplified filtering API #347
Comments
Related as a further syntactic sugar: edgedb/edgedb#3810 (comment) When writing a subquery select-by-id, it would be great if we had an even more compact syntax to refer to the linked entity by its ID without spelling out the query. |
What about other operators? Personally, I prefer something close to Graphql's style: FROM: filter: e.op(left, '>', right)
TO: filter: {left: {e.gt: right}}
FROM: filter: e.op(left, 'or', right)
TO: filter: {e.or: [left, right]}
... |
How would you combine new syntax and old if you have a bunch of eq filters and one non-eq? Would this be possible:
? Also, do we have to use |
I don't hate this, it's familiar to people and has better autocompletion than
This syntax wouldn't be allowed under the current proposal since I'm not planning to overload Both of these points make me think that my original proposal will be easier to explain/understand, namely that this "object filter" syntax should only work for exclusive properties or tuples. @elprans argued in favor of expanding this syntax to include all properties, s.t. this is a general purpose syntactic sugar for specifying any equality filter. But personally I like the idea of a special syntax only for uniquely specifying a single object. It's makes it visually obvious that you are selecting a single object, which makes cardinality inference less mysterious. Providing this syntax to include all properties invites additional questions, including the two above: "How do I use other operators?" and "How do I compose this with other expressions?". Both of these potential points of confusion are eliminated if we limit to exclusive properties/tuples, since there's never a reason to use non-equality operators or do |
We are doing this currently because we're being conservative and trying to keep the query builder semantics as close as possible to EdgeQL. Personally I agree this causes more confusion that it's worth. |
String IDs without |
Is there something blocking this from getting into EdgeDB? |
Implemented in the query builder: https://www.edgedb.com/docs/clients/js/querybuilder#select-a-single-object |
A proposal for simplified
filter
syntax for equality filters. The goal is to expand the scope of cardinality inference and provide a less verbose alternative toe.op(x, "=", y)
when specifying simple equality filters.In
e.select
, thefilter
key should also accept a plain JS object. The keys can correspond to an property/link name and can point to singleton expressions or plain JS literals.Current syntax
Proposed syntax
It's no longer necessary to include a reference to the scope variable
movie
or write thee.op()
expression, which is one of the bits of query builder syntax that is hardest to type quickly and least conducive to autocompletion.Type inference still works as expected. Filtering on a non-exclusive property returns an array:
If a referenced property/link has an exclusive constraint, the result will be a singleton.
This hold true for object-level exclusive constraints corresponding to a tuple of properties. (This is infeasible to implement using the
e.op
formulation.) e.g. if there is a compound constraint on(.title, .release_year)
the following would be inferred to be a singleton.An additional proposal is to support cardinality inference for "expression constraints". e.g.
The constraint's stored
expr
would be introspected to support the following:Non-exclusive
There is a question of whether the "object filter" syntax would support non-exclusive properties. @elprans objected to supporting this syntax exclusively for singleton/exclusive filtering. Filtering by equality on an exclusive vs nonexclusive property would look very different and possibly lead to confusion.
This proposal can be generalized to a way to specify any set of equality filters (#347)
This fixes the inconsistency, but makes it less visually obvious when a
filter
clause corresponds to a singleton filter. It also increases implementation complexity, since we'll need to statically determine whether keys of the "object filter" object correspond to an exclusive constraint, instead of simply checking if the value passed tofilter
is an object literal.The text was updated successfully, but these errors were encountered: