#Limit how much values fit into an array

14 messages · Page 1 of 1 (latest)

vast cedar
#

I found no way to limit the amount of values fit into an array, so I open this as a feature request.

I need something that matches this SQL implementation:

    string_array TEXT[] CHECK (cardinality(string_array) <= 3)
slim lotus
#

interesting. you can just check in the mutation, right? if (doc.arrayField.length < 3) { db.patch(..) }

vast cedar
#

But it would be nicer to have immediately a type-error if there is the possibility that we insert too many (like we get a type error for the wrong type etc.)

#

So that it can't happen in the first place that you insert to much items in an array

vast cedar
#

This could be implemented with tuples and that stuff right?

echo wraith
vast cedar
echo wraith
#

Oh are schemas not covered in that article

vast cedar
#

in SQL it would be:

    string_array TEXT[] CHECK (cardinality(string_array) <= 3)
echo wraith
#

You can use Zod for advanced schema validation, there are helpers for it, finding now

echo wraith
#

Also includes a breakdown from Jamie on why validation is limited currently