all repos — litestore @ 2dd7d785590a947b336c5f4f4ab589e1f7405ac9

A minimalist nosql document store.

Implemented sorting by fields.
h3rald h3rald@h3rald.com
Sat, 24 Feb 2018 19:19:00 +0100
commit

2dd7d785590a947b336c5f4f4ab589e1f7405ac9

parent

4af0b6d8d553c5775449eed61002e3bf784fd09f

M LiteStore_UserGuide.htmLiteStore_UserGuide.htm

@@ -5370,7 +5370,7 @@

<a name="HEAD-docs"></a> <h4>HEAD docs<a href="#document-top" title="Go to top"></a></h4> -<p>Retrieves all headers related to the docs resource and no content (this is probably not that useful, but at least it should make REST purists happy).</p> +<p>Retrieves all headers related to the <strong>docs</strong> resource and no content (this is probably not that useful, but at least it should make REST purists happy).</p> <a name="Example"></a> <h5>Example<a href="#document-top" title="Go to top"></a></h5>

@@ -5464,6 +5464,10 @@

<a name="<code>filter</code>-option"></a> <h5><code>filter</code> option<a href="#document-top" title="Go to top"></a></h5> +<div class="note"><p>API v3 Required</p> + +<p>This query string option has been introduced in version 3 of the LiteStore API.</p></div> + <p>Retrieve only JSON documents matching the specified filter expression.</p> <p>Filter expressions can be composed by one or more clauses joined together through <strong>or</strong> or <strong>and</strong> operators. Each clause must be composed exactly by:</p>

@@ -5495,6 +5499,10 @@

<a name="<code>select</code>-option"></a> <h5><code>select</code> option<a href="#document-top" title="Go to top"></a></h5> +<div class="note"><p>API v3 Required</p> + +<p>This query string option has been introduced in version 3 of the LiteStore API.</p></div> + <p>Retrieve JSON documents containing only the specified fields. Fields must be specified by comma-separated path/alias expression.</p> <p>Example: http://127.0.0.1:9500/docs/?select=$.name.first%20as%20FirstName,$.age%20as%20Age</p>

@@ -5502,9 +5510,19 @@

<a name="<code>sort</code>-option"></a> <h5><code>sort</code> option<a href="#document-top" title="Go to top"></a></h5> -<p>Sort by <strong>created</strong>, <strong>modified</strong>, and/or <strong>id</strong> (prepend <strong>-</strong> for DESC and <strong>+</strong> for ASC).</p> +<p>Sort by <strong>created</strong>, <strong>modified</strong>, <strong>id</strong> or a JSON path to a field (prepend <strong>-</strong> for DESC and <strong>+</strong> for ASC).</p> -<p>Example: http://127.0.0.1:9500/docs/?sort=-modified,-created</p> +<div class="note"><p>API v3 Required for JSON path support</p> + +<p>Support for JSON paths requires version 3 of the LiteStore API.</p></div> + +<p>Examples:</p> + +<ul> +<li>http://127.0.0.1:9500/docs/?sort=-modified,-created</li> +<li>http://127.0.0.1:9500/docs/?sort=-$.age,-$.name.first</li> +</ul> + <a name="Query-String-Options"></a> <h5>Query String Options<a href="#document-top" title="Go to top"></a></h5>

@@ -5584,7 +5602,7 @@ <p>Retrieves a list of documents in JSON format starting with the specified folder path (it must end with &lsquo;/&rsquo;).</p>

<div class="tip"><p>Supported query options</p> -<p>The same query options of the <strong>docs</strong> resources are supported.</p></div> +<p>The same query options of the <strong>docs</strong> resource are supported.</p></div> <a name="Example"></a> <h5>Example<a href="#document-top" title="Go to top"></a></h5>
M admin/md/api_docs.mdadmin/md/api_docs.md

@@ -1,3 +1,12 @@

+{{v3-option => +> %note% +> API v3 Required +> +> This query string option has been introduced in version 3 of the LiteStore API. + +}} + + ### docs (LiteStore Documents) A document is the main resource type managed by LiteStore. Any LiteStore document can be represented as a JSON object exposing the following properties:

@@ -119,7 +128,7 @@ ```

#### HEAD docs -Retrieves all headers related to the docs resource and no content (this is probably not that useful, but at least it should make REST purists happy). +Retrieves all headers related to the **docs** resource and no content (this is probably not that useful, but at least it should make REST purists happy). ##### Example

@@ -203,6 +212,8 @@ Example: http://127.0.0.1:9500/docs/?tags=tag1,tag2

##### `filter` option +{{v3-option}} + Retrieve only JSON documents matching the specified filter expression. Filter expressions can be composed by one or more clauses joined together through **or** or **and** operators. Each clause must be composed exactly by:

@@ -224,6 +235,8 @@ * http://127.0.0.1:9500/docs/?filter=$.age%20gte%2018%20or%20$.skills%20contains%20"maths"

* http://127.0.0.1:9500/docs/?filter=$.name.first&20eq%20"Jack"%20or%20$.fav\_food[0]%20eq%20"pizza" ##### `select` option + +{{v3-option}} Retrieve JSON documents containing only the specified fields. Fields must be specified by comma-separated path/alias expression.

@@ -231,9 +244,17 @@ Example: http://127.0.0.1:9500/docs/?select=$.name.first%20as%20FirstName,$.age%20as%20Age

##### `sort` option -Sort by **created**, **modified**, and/or **id** (prepend **-** for DESC and **+** for ASC). +Sort by **created**, **modified**, **id** or a JSON path to a field (prepend **-** for DESC and **+** for ASC). -Example: http://127.0.0.1:9500/docs/?sort=-modified,-created +> %note% +> API v3 Required for JSON path support +> +> Support for JSON paths requires version 3 of the LiteStore API. + +Examples: + +* http://127.0.0.1:9500/docs/?sort=-modified,-created +* http://127.0.0.1:9500/docs/?sort=-$.age,-$.name.first ##### Query String Options

@@ -314,7 +335,7 @@

> %tip% > Supported query options > -> The same query options of the **docs** resources are supported. +> The same query options of the **docs** resource are supported. ##### Example
M admin/md/getting-started.mdadmin/md/getting-started.md

@@ -5,12 +5,12 @@ ### Downloading Pre-built Binaries

The easiest way to get LiteStore is by downloading one of the prebuilt binaries from the [Github Release Page][release]: - * [LiteStore for Mac OS X (x64)](https://github.com/h3rald/litestore/releases/download/{{$version}}litestore_{{$version}}_macosx_x64.zip) -- Compiled on OS X El Capitan (LLVM CLANG 7.0.0) - * [LiteStore for Windows (x64)](https://github.com/h3rald/litestore/releases/download/{{$version}}/litestore_{{$version}}_windows_x64.zip) -- Cross-compiled on OS X El Capitan (MinGW-w64 GCC 4.8.2) - * [LiteStore for Windows (x86)](https://github.com/h3rald/litestore/releases/download/{{$version}}/litestore_{{$version}}_windows_x86.zip) -- Cross-compiled on OS X El Capitan (MinGW-w64 GCC 4.8.2) - * [LiteStore for Linux (x64)](https://github.com/h3rald/litestore/releases/download/{{$version}}/litestore_{{$version}}_linux_x64.zip) -- Cross-compiled on OS X El Capitan (GNU GCC 4.8.1) - * [LiteStore for Linux (x86)](https://github.com/h3rald/litestore/releases/download/{{$version}}/litestore_{{$version}}_linux_x86.zip) -- Cross-compiled on OS X El Capitan (GNU GCC 4.8.1) - * [LiteStore for Linux (ARM)](https://github.com/h3rald/litestore/releases/download/{{$version}}/litestore_{{$version}}_linux_arm.zip) -- Cross-compiled on OS X El Capitan (GNU GCC 4.8.2) + * [LiteStore for Mac OS X (x64)](https://github.com/h3rald/litestore/releases/download/{{$version}}litestore_{{$version}}_macosx_x64.zip) + * [LiteStore for Windows (x64)](https://github.com/h3rald/litestore/releases/download/{{$version}}/litestore_{{$version}}_windows_x64.zip) + * [LiteStore for Windows (x86)](https://github.com/h3rald/litestore/releases/download/{{$version}}/litestore_{{$version}}_windows_x86.zip) + * [LiteStore for Linux (x64)](https://github.com/h3rald/litestore/releases/download/{{$version}}/litestore_{{$version}}_linux_x64.zip) + * [LiteStore for Linux (x86)](https://github.com/h3rald/litestore/releases/download/{{$version}}/litestore_{{$version}}_linux_x86.zip) + * [LiteStore for Linux (ARM)](https://github.com/h3rald/litestore/releases/download/{{$version}}/litestore_{{$version}}_linux_arm.zip) ### Installing using Nimble
M build_guidebuild_guide

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

do (cat "${page}"; printf "\n\n") >> LiteStore_UserGuide.md done -hastyscribe --field/version:1.2.0 LiteStore_UserGuide.md +hastyscribe --field/version:1.3.0 LiteStore_UserGuide.md rm LiteStore_UserGuide.md mv LiteStore_UserGuide.htm .. cd ..
M lib/api_v3.nimlib/api_v3.nim

@@ -18,18 +18,6 @@ logger

# Helper procs -proc orderByClauses*(str: string): string = - var clauses = newSeq[string]() - var fragments = str.split(",") - for f in fragments: - var matches = @["", ""] - if f.find(peg"{[-+ ]} {(id / created / modified)}", matches) != -1: - if matches[0] == "-": - clauses.add("$1 DESC" % matches[1]) - else: - clauses.add("$1 ASC" % matches[1]) - return clauses.join(", ") - proc sqlOp(op: string): string = let table = newStringTable() table["not eq"] = "<>"

@@ -41,6 +29,26 @@ table["lte"] = "<="

table["contains"] = "contains" return table[op] +proc orderByClauses*(str: string): string = + var clauses = newSeq[string]() + var fragments = str.split(",") + let clause = peg""" + clause <- {[-+]} {field} + field <- ('id' / 'created' / 'modified' / path) + path <- '$' (objField)+ + ident <- [a-zA-Z0-9_]+ + objField <- '.' ident + """ + for f in fragments: + var matches = @["", ""] + if f.find(clause, matches) != -1: + let direction = matches[0] + let field = "json_extract(documents.data, '$1')" % matches[1] + if matches[0] == "-": + clauses.add("$1 DESC" % field) + else: + clauses.add("$1 ASC" % field) + return clauses.join(", ") proc selectClause*(str: string, options: var QueryOptions) = let tokens = """
M litestore.nimblelitestore.nimble

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

[Package] name = "litestore" -version = "1.2.0" +version = "1.3.0" author = "Fabio Cevasco" description = "Self-contained, lightweight, RESTful document store." license = "MIT"
M test/http_api.nimtest/http_api.nim

@@ -176,4 +176,9 @@ "age": 31

} check(json["data"] == testdata) + test "GET documents sorting by fields": + var rget = jget("docs/?sort=+$.age,+$.name.first") + var json = rget.body.parseJson + check(json["results"][2]["data"]["age"] == %31) + check(json["results"][5]["data"]["name"]["first"] == %"Hart")