edgedb
edgedb copied to clipboard
Sets with zero or one elements are assumed to be singular
This is more an issue with the client libraries than edgedb itself, but still
My example in Rust is:
with users := (select User filter ...)
select users { name, email, username }
With an output type of Vec<User>
This will work fine if it finds more than one user, but die if it got zero or one users.
It's really atrocious in Rust because it just gives a blank DescriptorMismatch as the error. If it's in a larger query it's a pretty subtle bug.
Per the thread, the workaround is to do
with users := (select User filter ...)
select (users union {}) { name, email, username }
to force a set
Maybe a new function assert_many()
to force the cardinality. Though it wouldn't be an assertion.
Does
with multi users :=
do the trick? Oh that's not valid syntax. Maybe that could be the solution?
Sorry, forgot to come back and update this - multi
is actually the better solution than the union thing. It goes on the final shape rather than the with
variable.
I still think the db should be able to put an empty vec for no items, a single item vec for one item, rather than dying, but multi
is semantically good as a syntax solution.
select multi users
? That isn't valid syntax either. I think that only works inside of a shape.
This works:
select { multi u := users }
not very pretty though, and it nests the output.
Yes, that