all repos — litestore @ 7d6d4798459e6cc27e4763c10eba034dbe78c4bc

A minimalist nosql document store.

Handling simulaneous opening of multiple stores.
h3rald h3rald@h3rald.com
Sun, 15 Mar 2020 14:48:50 +0100
commit

7d6d4798459e6cc27e4763c10eba034dbe78c4bc

parent

ab5a1bb2885f9f6dd5e9a82b8bc3e72c0d0b2e51

M build_guidebuild_guide

@@ -28,7 +28,7 @@ for page in ${pages[@]}

do (cat "${page}"; printf "\n\n") >> LiteStore_UserGuide.md done -hastyscribe --field/version:1.8.0 LiteStore_UserGuide.md +hastyscribe --field/version:1.9.0 LiteStore_UserGuide.md rm LiteStore_UserGuide.md mv LiteStore_UserGuide.htm .. cd ../..
M src/litestore.nimsrc/litestore.nim

@@ -1,6 +1,7 @@

import strutils, strtabs, + tables, os, uri, httpcore,

@@ -37,7 +38,7 @@ for meth, content in v.pairs:

if content.hasKey("auth"): auth["access"][k][meth] = content["auth"] -proc processConfigSettings() = +proc processConfigSettings(LS: var LiteStore) = # Process config settings if present and if no cli settings are set if LS.config != newJNull() and LS.config.hasKey("settings"): let settings = LS.config["settings"]

@@ -103,7 +104,7 @@ quit(0)

else: quit(resp.code.int) -proc setup*(open = true) = +proc setup*(LS: var LiteStore, open = true) = if not LS.file.fileExists: try: LOG.debug("Creating datastore: ", LS.file)

@@ -117,7 +118,6 @@ LS.store = LS.file.openDatastore()

try: LS.store.upgradeDatastore() except: - echo getCurrentExceptionMsg() fail(203, "Unable to upgrade datastore '$1'" % [LS.file]) if LS.mount: try:

@@ -128,16 +128,7 @@ fail(202, "Unable to mount directory '$1'" % [LS.directory])

except: fail(201, "Unable to open datastore '$1'" % [LS.file]) -when isMainModule: - - # Manage vacuum operation separately - if LS.operation == opVacuum: - setup(false) - vacuum LS.file - else: - # Open Datastore - setup(true) - +proc initStore(LS: var LiteStore) = if LS.configFile == "": # Attempt to retrieve config.json from system documents let options = newQueryOptions(true)

@@ -147,7 +138,7 @@ LS.config = rawDoc.parseJson()["data"]

if LS.config != newJNull(): # Process config settings - processConfigSettings() + LS.processConfigSettings() # Process auth from config settings processAuthConfig(LS.config, LS.auth)

@@ -170,23 +161,56 @@ fail(110, "--uri option not specified")

if LS.execution.operation == "" and LS.operation == opExecute: fail(111, "--operation option not specified") - - case LS.operation: - of opRun: - LS.serve - runForever() - of opImport: - LS.store.importDir(LS.directory, LS.manageSystemData) - of opExport: - LS.store.exportDir(LS.directory, LS.manageSystemData) - of opDelete: - LS.store.deleteDir(LS.directory, LS.manageSystemData) - of opOptimize: - LS.store.optimize - of opExecute: - executeOperation() - else: - discard + +# stores: { +# test: { +# file: 'path/to/test.db', +# config: { +# resources: {}, +# signature: '' +# } +# } +# } +proc initStores() = + LSDICT["main"] = LS + if LS.config.kind == JObject and LS.config.hasKey("stores"): + for k, v in LS.config["stores"].pairs: + # TODO error handling + LSDICT[k] = initLiteStore() + LSDICT[k].file = v["file"].getStr + if v.hasKey("config"): + LSDICT[k].config = v["config"] + for k in LSDICT.keys: + LOG.info("Initializing store '$1'" % k) + LSDICT[k].setup() + LSDICT[k].initStore() + +when isMainModule: + + # Manage vacuum operation separately + if LS.operation == opVacuum: + LS.setup(false) + vacuum LS.file + else: + # Open Datastore + #LS.setup(true) + initStores() + case LS.operation: + of opRun: + LS.serve + runForever() + of opImport: + LS.store.importDir(LS.directory, LS.manageSystemData) + of opExport: + LS.store.exportDir(LS.directory, LS.manageSystemData) + of opDelete: + LS.store.deleteDir(LS.directory, LS.manageSystemData) + of opOptimize: + LS.store.optimize + of opExecute: + executeOperation() + else: + discard else:
M src/litestorepkg/examples/system/config.jsonsrc/litestorepkg/examples/system/config.json

@@ -3,6 +3,14 @@ "settings": {

"log": "debug", "port": 9200 }, + "stores": { + "test1": { + "file": "test1.db" + }, + "test2": { + "file": "test2.db" + } + }, "resources": { "/docs/vehicles/*": { "GET": {
M src/litestorepkg/lib/config.nimsrc/litestorepkg/lib/config.nim

@@ -1,6 +1,6 @@

const pkgName* = "litestore" - pkgVersion* = "1.8.0" + pkgVersion* = "1.9.0" pkgAuthor* = "Fabio Cevasco" pkgDescription* = "Self-contained, lightweight, RESTful document store." pkgLicense* = "MIT"
M src/litestorepkg/lib/types.nimsrc/litestorepkg/lib/types.nim

@@ -115,6 +115,19 @@ id: string,

version: string ] +proc initLiteStore*(): LiteStore = + result.config = newJNull() + result.configFile = "" + result.cliSettings = newJNull() + result.directory = "" + result.manageSystemData = false + result.file = "" + result.mount = false + result.readonly = false + result.loglevel = "warn" + result.auth = newJNull() + result.authFile = "" + proc httpMethod*(meth: string): HttpMethod = case meth: of "GET":

@@ -232,7 +245,9 @@ PEG_URL = peg"""^\/({(v\d+)} \/) {([^\/]+)} (\/ {(.+)} / \/?)$"""

# Initialize LiteStore var LS* {.threadvar.}: LiteStore +var LSDICT* {.threadvar.}: Table[string, LiteStore] var TAB_HEADERS* {.threadvar.}: array[0..2, (string, string)] +LSDICT = initTable[string, LiteStore]() LS.appversion = pkgVersion LS.appname = appname