I am working on a library that allows re-ordering rows of an Ecto schema based on an integer column.
Right now, the column is hard-coded to always be
:position. Of course, this should become configureable.
However, the code contains statements such as the following:
|> Ecto.Multi.update_all(:decremented_higher_siblings_1, from( p in later_siblings, update: [set: [position: fragment("- (? - 1)", p.position)]]), ).
Note here the
update: [set: ...] part (see the documentation of
Ecto.Query.field exists to set a dynamic field name, but as
update uses a keyword list, I have no idea how to properly set the keyword list key there (as the line still is supposed to be read as macro, with the
p variable available).
How to do this?