all repos — litestore @ 9210fa51fc9e620d5e71408e3708f92b59dfeb28

A minimalist nosql document store.

Now also checking GET request headers for application/json.
h3rald h3rald@h3rald.com
Sun, 25 Jan 2015 18:09:39 +0100
commit

9210fa51fc9e620d5e71408e3708f92b59dfeb28

parent

20298800ebc9a4722527d6921abdca798add0e9c

3 files changed, 4 insertions(+), 30 deletions(-)

jump to
M litestore.nimlitestore.nim

@@ -21,31 +21,6 @@

{.compile: "vendor/sqlite/libsqlite3.c".} {.passC: "-DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS".} -# Test -when false: - var file = "test.ls" - if file.fileExists: - file.removeFile - createDatastore(file) - var store = file.openDatastore - var id1 = store.createDocument "This is a test document" - var id2 = store.createDocument "This is another test document" - var id3 = store.createDocument "This is yet another test document" - store.createTag "test1", id1 - store.createTag "test2", id2 - store.createTag "test3", id2 - store.createTag "test", id1 - store.createTag "test", id2 - store.createTag "test", id3 - var opts = newQueryOptions() - #opts.tags = "test,test2" - #opts.search = "another yet" - store.packDir("nimcache") - "test".createDir - "test".setCurrentDir - store.unpackDir("nimcache") - echo store.destroyDocumentsByTag("$dir:nimcache") - when isMainModule: # Initialize Datastore if not LS.file.fileExists:
M server.nimserver.nim

@@ -1,5 +1,4 @@

-import asynchttpserver, asyncdispatch, times, strutils, pegs -from strtabs import StringTableRef, newStringTable +import asynchttpserver, asyncdispatch, times, strutils, pegs, strtabs import types, api proc getReqInfo(req: Request): string =

@@ -45,7 +44,7 @@ var matches = @[""]

if req.url.path.rDocs(matches): if matches[0] != "": # Retrieve a single document - if req.url.query.contains("raw=true"): + if req.url.query.contains("raw=true") or req.headers["Content-Type"] == "application/json": return LS.getRawDocument(matches[0]) else: return LS.getDocument(matches[0])
M types.nimtypes.nim

@@ -39,10 +39,10 @@ content: string,

headers: StringTableRef] const - CT_JSON* = {"Content-type": "application/json"} + CT_JSON* = {"Content-Type": "application/json"} proc ctHeader*(ct: string): StringTableRef = - return {"Content-type": ct}.newStringTable + return {"Content-Type": ct}.newStringTable proc ctJsonHeader*(): StringTableRef = return CT_JSON.newStringTable