INNER CODE UNIT · Python

upsert

jsbroks/coco-annotator · backend/database/__init__.py:25

def upsert(model, query=None, update=None):

    if not update:
        update = query

    if not query:
        return None

    found = model.objects(**query)

    if found.first():
        return found.modify(new=True, **update)

    new_model = model(**update)
    new_model.save()

    return new_model

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…