all repos — litestore @ 0991016883d61d6c8a789df61ae287ebed127a6e

A minimalist nosql document store.

JSON data is no longer represented as string.
h3rald h3rald@h3rald.com
Mon, 07 Sep 2015 22:31:04 +0200
commit

0991016883d61d6c8a789df61ae287ebed127a6e

parent

cdf8455e669b92b6396c612090bb72d9a548d3a5

1 files changed, 17 insertions(+), 8 deletions(-)

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

@@ -94,25 +94,34 @@ tags.add(%($(tag[0])))

if doc.len == 1: # COUNT(id) return %(doc[0].parseInt) - var res = newSeq[tuple[key: string, val: JsonNode]](0) + result = newJObject() var count = 0 + var jsondoc = false for s in cols: var key = s count.inc - if key == "searchable" or key == "binary" or key == "content_type": - continue + var rawvalue = doc[count-1] + var value:JsonNode if s.contains(" "): # documents.id AS id... let chunks = s.split(" ") key = chunks[chunks.len-1] - var value:JsonNode - if doc[count-1] == "": + case key: + of "searchable", "binary": + continue + of "content_type": + if rawvalue == "application/json": + jsondoc = true + else: + discard + if rawvalue == "": value = newJNull() else: value = %doc[count-1] - res.add((key, value)) - res.add(("tags", %tags)) - return %res + result[key] = value + if jsondoc: + result["data"] = result["data"].getStr().parseJson() + result["tags"] = %tags proc toPlainText*(s: string): string = var tags = peg"""'<' [^>]+ '>'"""