all repos — litestore @ 3d1795c5cd9327afb3dd7c88c312607af2ff2770

A minimalist nosql document store.

Improved robustness of patch operation.
* Closes #28.
h3rald h3rald@h3rald.com
Fri, 25 Sep 2015 21:48:31 +0200
commit

3d1795c5cd9327afb3dd7c88c312607af2ff2770

parent

e3659f5d0c22ff356487b48f6ee27e64313a7134

1 files changed, 6 insertions(+), 2 deletions(-)

jump to
M lib/api_v1.nimlib/api_v1.nim

@@ -88,11 +88,12 @@ var matches = @[""]

if path.find(peg"^\/tags\/{\d+}$", matches) == -1: raise newException(EInvalidRequest, "cannot patch path '$1'" % path) let index = matches[0].parseInt + LOG.debug("- PATCH -> $1 tag index '$2' - Total tags: $3." % [op, $index, $tags.len]) case op: of "remove": let tag = tags[index] if not tag.startsWith("$"): - system.delete(tags, index) + tags[index] = "" # Not removing element, otherwise subsequent indexes won't work! else: raise newException(EInvalidRequest, "Cannot remove system tag: $1" % tag) of "add":

@@ -272,6 +273,8 @@ if not item.hasKey("value"):

item["value"] = %"" try: apply = applyPatchOperation(tags, item["op"].str, item["path"].str, item["value"].str) + if not apply: + break except: return resError(Http400, "Bad request - $1" % getCurrentExceptionMsg()) else:

@@ -282,7 +285,8 @@ try:

for t1 in jdoc["tags"].items: discard LS.store.destroyTag(t1.str, id, true) for t2 in tags: - LS.store.createTag(t2, id, true) + if t2 != "": + LS.store.createTag(t2, id, true) except: return resError(Http500, "Unable to patch document '$1' - $2" % [id, getCurrentExceptionMsg()]) return LS.getRawDocument(id)