Skip to main content

inject_update

Function inject_update 

Source
pub fn inject_update(
    update: &mut Value,
    fields: &[(FieldName, Value)],
) -> Result<(), RewriteError>
Expand description

Injects the tenancy fields into the doc and upsert sub-objects of an _update body (docs/04 §3).

An update never replaces a whole document, so the fields are stamped into whichever sub-documents are present: a partial doc (re-asserting the tenancy fields, harmless on an existing doc) and the upsert (so an upsert that creates the document still carries its isolation fields). A sub-key that is absent is skipped; a script-only update with no upsert injects nothing (the targeted document already carries the fields).

§Errors

Returns RewriteError::NotAnObject if update itself, or a present doc/upsert, is not a JSON object, or RewriteError::ReservedFieldCollision if a sub-document already contains an injected field (a client must not pre-seed a tenancy field, docs/03).