all repos — litestore @ 09ab81488bb9630c9755cb9c7ad05bd0b65d1c8a

A minimalist nosql document store.

Added tests.
h3rald h3rald@h3rald.com
Sun, 04 Feb 2018 18:07:21 +0100
commit

09ab81488bb9630c9755cb9c7ad05bd0b65d1c8a

parent

b55f93779979da1b976ad89ed0698953c3afbaf0

2 files changed, 11 insertions(+), 8 deletions(-)

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

@@ -34,6 +34,7 @@ raise newException(EInvalidTag, "Invalid tag '$1'" % tag)

result = result & "AND " & doc_id_col & " IN (" & select_tagged & tag & "') " proc prepareSelectDocumentsQuery*(options: var QueryOptions): string = + var tables = options.tables result = "SELECT " if options.search.len > 0: if options.select[0] != "COUNT(docid)":

@@ -51,22 +52,20 @@ if options.limit > 0:

innerSelect = innerSelect & "LIMIT " & $options.limit if options.offset > 0: innerSelect = innerSelect & " OFFSET " & $options.offset - result = result & options.select.join(", ") - options.tables = options.tables & @["documents"] + tables = options.tables & @["documents"] result = result & options.select.join(", ") - result = result & " FROM " & options.tables.join(", ") & " JOIN (" & innerSelect & ") as ranktable USING(docid) JOIN searchdata USING(docid) " + result = result & " FROM " & tables.join(", ") & " JOIN (" & innerSelect & ") as ranktable USING(docid) JOIN searchdata USING(docid) " result = result & "WHERE 1=1 " else: - options.tables = options.tables & @["searchdata"] + tables = options.tables & @["searchdata"] result = result & options.select.join(", ") - result = result & " FROM "&options.tables.join(", ")&" " + result = result & " FROM "&tables.join(", ")&" " result = result & "WHERE 1=1 " options.orderby = "" else: - if not options.tables.contains "documents": - options.tables = options.tables & @["documents"] + tables = options.tables & @["documents"] result = result & options.select.join(", ") - result = result & " FROM "&options.tables.join(", ")&" WHERE 1=1 " + result = result & " FROM "&tables.join(", ")&" WHERE 1=1 " if options.single: result = result & "AND id = ?" var doc_id_col: string
M test/http_api.nimtest/http_api.nim

@@ -119,6 +119,10 @@ rhead = jhead("docs/test/")

check(rhead.status == "200 OK") var rget = jget("docs/?search=Lorem&contents=false") check(rget.body.parseJson["total"] == %5) + rget = jget("docs/?filter=$.age%20gte%2034%20and%20$.age%20lte%2036%20and%20$.tags%20contains%20%22labore%22") + check(rget.body.parseJson["total"] == %1) + rget = jget("docs/?filter=$.age%20eq%2034%20or%20$.age%20eq%2036%20or%20$.eyeColor%20eq%20\"brown\"") + check(rget.body.parseJson["total"] == %5) for i in ids: jdelete("docs/$1" % i) check(info("total_documents") == %0)