I want to implement an UPDATE SET statement with named parameters? Is it possible?
For an object like:
{
_id: 1,
name: "new_name",
password: "new_password",
subscribed: true,
email: "[email protected]"
}
This is my guess:
UPDATE
accounts
SET
$(this:name) = $(this:csv)
WHERE
_id = $(this._id)
The object fields may vary depending on requests sent, so I don't want to "hard code" the parameters in.
this
isn't gonna do any magic for you here. – Fluethis:csv
automatically converts it into a kind of.join(",")
thing. I was also thinking about using aselect $(this:csv)
somehow with the update. – Xylo:name
and:csv
do indeed provide some basic automation. But in case of aSET
operation, you need a combination. So unless you opt for a multi-row update approach, you will have to use those columns explicitly. – Flue