plain value (set) | { status: "done" }
| json_set(_doc, '$.status', json(?))
|
u.set | ({ set }) => ({ status: set("done") })
| json_set(_doc, '$.status', json(?))
|
u.unset | ({ unset }) => ({ draft: unset() })
| json_remove(_doc, '$.draft')
|
u.inc | ({ inc }) => ({ views: inc(1) })
| json_set(_doc, '$.views', COALESCE(json_extract(_doc, '$.views'), 0) + ?)
|
u.mul | ({ mul }) => ({ price: mul(1.1) })
| json_set(_doc, '$.price', COALESCE(json_extract(_doc, '$.price'), 0) * ?)
|
u.min | ({ min }) => ({ lowest: min(10) })
| json_set(_doc, '$.lowest', MIN(COALESCE(json_extract(_doc, '$.lowest'), ?), ?))
|
u.max | ({ max }) => ({ highest: max(90) })
| json_set(_doc, '$.highest', MAX(COALESCE(json_extract(_doc, '$.highest'), ?), ?))
|
u.push | ({ push }) => ({ logs: push(entry) })
| json_set(_doc, '$.logs', json_insert(COALESCE(json_extract(_doc, '$.logs'), json('[]')), '$[#]', json(?)))
|
u.addToSet | ({ addToSet }) => ({ tags: addToSet("urgent") })
| json_set(_doc, '$.tags', CASE WHEN EXISTS (SELECT 1 FROM json_each(...) WHERE value = ?) THEN ... ELSE json_insert(..., '$[#]', json(?)) END)
|
u.pull | ({ pull }) => ({ tags: pull("urgent") })
| json_set(_doc, '$.tags', (SELECT json_group_array(value) FROM json_each(...) WHERE value <> ?))
|
u.setOnInsert | ({ setOnInsert }) => ({ status: setOnInsert("new") })
| applied only when upsert inserts a new row
|
nested path | ({ set }) => ({ "profile.city": set("Seoul") })
| json_set(_doc, '$.profile.city', json(?))
|
combined | ({ inc, addToSet }) => ({ views: inc(1), tags: addToSet("hot") })
| json_set(json_set(_doc, '$.views', ... + ?), '$.tags', ...)
|