vapor/sql-kit

Lists Should be Grouped

calebkleveter opened this issue · 1 comments

When a SQLList is serialized, there is no grouping around the elements that are written. This means that sub-lists could get parsed incorrectly by the database.

For example, if I am trying to update a single model that uses soft-deletion in Postgres, the query looks something like this:

UPDATE model SET id = 42 WHERE id = 42 AND deleted_at > '2019-11-25T19:47:20' OR deleted_at = NULL

The problem is that in this case, the deleted_at column predicates should be grouped together, but instead Postgres groups the predicates before and after the AND statement first. What this means is that Postgres tries to set all the models that aren't deleted to have an ID of 42.

You can put an expression in a group using SQLGroupExpression. I don't think we can change SQLList's behavior since (IIRC) there are some situations where it's used that parens are not valid.