all repos — litestore @ 785f6a3268f6316fd7390d6985ccfff9956d7531

A minimalist nosql document store.

Added auth.json lookup from system documents.
h3rald h3rald@h3rald.com
Sat, 08 Feb 2020 12:40:51 +0100
commit

785f6a3268f6316fd7390d6985ccfff9956d7531

parent

04733dd75300cb3e5c5243c086c3bc7af2494304

2 files changed, 15 insertions(+), 4 deletions(-)

jump to
M src/litestore.nimsrc/litestore.nim

@@ -2,7 +2,8 @@ import

strutils, os, uri, - httpcore + httpcore, + json import litestorepkg/lib/types, litestorepkg/lib/logger,

@@ -98,6 +99,13 @@ vacuum LS.file

else: # Open Datastore setup(true) + +if LS.auth == newJNull(): + # Attempt to retrieve auth.json from system documents + let options = newQueryOptions(true) + let rawDoc = LS.store.retrieveRawDocument("auth.json", options) + if rawDoc != "": + LS.auth = rawDoc.parseJson() case LS.operation: of opRun:
M src/litestorepkg/lib/types.nimsrc/litestorepkg/lib/types.nim

@@ -121,7 +121,10 @@ "Access-Control-Allow-Headers": "Authorization, Content-Type",

"Server": LS.appname & "/" & LS.appversion } -proc newQueryOptions*(): QueryOptions = - return QueryOptions(select: @["documents.id AS id", "documents.data AS data", "content_type", "binary", "searchable", "created", "modified"], - single: false, limit: 0, offset: 0, orderby: "", tags: "", search: "", folder: "", like: "", +proc newQueryOptions*(system = false): QueryOptions = + var select = @["documents.id AS id", "documents.data AS data", "content_type", "binary", "searchable", "created", "modified"] + if system: + select = @["system_documents.id AS id", "system_documents.data AS data", "content_type", "binary", "created", "modified"] + return QueryOptions(select: select, + single: false, limit: 0, offset: 0, orderby: "", tags: "", search: "", folder: "", like: "", system: system, createdAfter: "", createdBefore: "", modifiedAfter: "", modifiedBefore: "", jsonFilter: "", jsonSelect: newSeq[tuple[path: string, alias: string]](), tables: newSeq[string]())