all repos — litestore @ 045149148c3b3b1002cee32bf4883a2db5379c1c

A minimalist nosql document store.

Implemented --delete (removed --purge).
h3rald h3rald@h3rald.com
Sat, 28 Feb 2015 15:16:12 +0100
commit

045149148c3b3b1002cee32bf4883a2db5379c1c

parent

bc09339019e165067f33d3e84f6a5b28586aadec

8 files changed, 40 insertions(+), 22 deletions(-)

jump to
D app/compile

@@ -1,4 +0,0 @@

-#!/usr/bin/env bash -cat md/metadata.md md/overview.md md/getting-started.md md/usage.md md/api.md md/credits.md > LiteStore_UserGuide.md -hastyscribe LiteStore_UserGuide.md -rm LiteStore_UserGuide.md
A build_guide

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

+#!/usr/bin/env bash +cd app +cat md/metadata.md md/overview.md md/getting-started.md md/usage.md md/api.md md/credits.md > LiteStore_UserGuide.md +hastyscribe LiteStore_UserGuide.md +rm LiteStore_UserGuide.md +cd ..
M lib/cli.nimlib/cli.nim

@@ -16,7 +16,6 @@ port*: int

operation = opRun directory = "" readonly = false - purge = false logLevel = lvlInfo var f = newStringStream(cfgfile)

@@ -55,16 +54,16 @@ usage* = appname & " v" & version & " - Lightweight REST Document Store" & """

(c) 2015 Fabio Cevasco Usage: - LS [-p:<port> -a:<address>] [<file>] [--pack:<directory> | --unpack:<directory>] + LS [-p:<port> -a:<address>] [<file>] [--import:<directory> | --export:<directory> | --delete:<directory>] Options: -a, --address Specify address (default: 0.0.0.0). - --export Export the previously-packed specified directory to the current directory. + -d, --delete Delete the previously-imported specified directory. + --export Export the previously-imported specified directory to the current directory. -h, --help Display this message. --import Import the specified directory (Store all its contents). -l, --log Specify the log level: debug, info, warn, error, fatal, none (default: info) -p, --port Specify port number (default: 9500). - --purge Delete exported files (used in conjunction with --export). -r, --readonly Allow only data retrieval operations. -v, --version Display the program version. """

@@ -98,8 +97,9 @@ if val == "":

fail(105, "Directory to export not specified.") operation = opExport directory = val - of "purge": - purge = true + of "delete", "d": + operation = opDelete + directory = val of "version", "v": echo version quit(0)

@@ -121,7 +121,6 @@ LS.port = port

LS.address = address LS.operation = operation LS.file = file -LS.purge = purge LS.directory = directory LS.appversion = version LS.readonly = readonly
M lib/core.nimlib/core.nim

@@ -188,7 +188,7 @@ d_searchable = 0

discard store.createDocument(d_id, d_contents, d_ct, d_binary, d_searchable) store.db.exec(SQL_INSERT_TAG, "$dir:"&dir, d_id) -proc exportDir*(store: Datastore, dir: string, purge = false) = +proc exportDir*(store: Datastore, dir: string) = let docs = store.db.getAllRows(SQL_SELECT_DOCUMENTS_BY_TAG, "$dir:"&dir) for doc in docs: let file = doc[0]

@@ -199,14 +199,14 @@ else:

data = doc[1] file.parentDir.createDir file.writeFile(data) - if purge: + +proc deleteDir*(store: Datastore, dir: string) = store.db.exec(SQL_DELETE_DOCUMENTS_BY_TAG, "$dir:"&dir) + store.db.exec(SQL_DELETE_SEARCHCONTENTS_BY_TAG, "$dir:"&dir) + store.db.exec(SQL_DELETE_TAGS_BY_TAG, "$dir:"&dir) proc destroyDocumentsByTag*(store: Datastore, tag: string): int64 = result = 0 var ids = store.db.getAllRows(SQL_SELECT_DOCUMENT_IDS_BY_TAG, tag) for id in ids: result.inc(store.destroyDocument(id[0]).int) - - -
M lib/queries.nimlib/queries.nim

@@ -123,7 +123,19 @@ SELECT COUNT(id) FROM documents

""" const SQL_DELETE_DOCUMENTS_BY_TAG* = sql""" -DELETE FROM documents, tags -WHERE documents.id = tags.document_id AND -tag_id = ? +DELETE FROM documents +WHERE documents.id IN +(SELECT document_id FROM tags WHERE tag_id = ?) +""" + +const SQL_DELETE_SEARCHCONTENTS_BY_TAG* = sql""" +DELETE FROM searchcontents +WHERE document_id IN +(SELECT document_id FROM tags WHERE tag_id = ?) +""" + +const SQL_DELETE_TAGS_BY_TAG* = sql""" +DELETE FROM tags +WHERE document_id IN +(SELECT document_id FROM tags WHERE tag_id = ?) """
M lib/types.nimlib/types.nim

@@ -23,7 +23,7 @@ tag*: string

startswith*: bool endswith*: bool negated*: bool - Operation* = enum opRun, opImport, opExport + Operation* = enum opRun, opImport, opExport, opDelete LiteStore* = object store*: Datastore address*: string

@@ -31,7 +31,6 @@ port*: int

operation*: Operation directory*: string file*: string - purge*: bool readonly*: bool appname*: string appversion*: string
M litestore.nimlitestore.nim

@@ -36,7 +36,9 @@ case LS.operation:

of opImport: LS.store.importDir(LS.directory) of opExport: - LS.store.exportDir(LS.directory, LS.purge) + LS.store.exportDir(LS.directory) + of opDelete: + LS.store.deleteDir(LS.directory) of opRun: LS.serve runForever()
A run_app

@@ -0,0 +1,4 @@

+#!/usr/bin/env bash +./litestore --delete:app +./litestore --import:app +./litestore