all repos — litestore @ adc1bfddded01e699452a5ea8c4f70bf645c2721

A minimalist nosql document store.

Added support for multiple order clauses.
* Closes #38.
h3rald h3rald@h3rald.com
Sun, 08 May 2016 14:17:32 +0200
commit

adc1bfddded01e699452a5ea8c4f70bf645c2721

parent

5fab9e284cfe22fb2435be396c4a45af23267baa

4 files changed, 50 insertions(+), 24 deletions(-)

jump to
M LiteStore_UserGuide.htmLiteStore_UserGuide.htm

@@ -225,6 +225,11 @@ <ul>

<li><a href="#Example">Example</a></li> </ul> </li> + <li><a href="#POST.docs.:folder.">POST docs/:folder/</a> + <ul> + <li><a href="#Example">Example</a></li> + </ul> + </li> <li><a href="#HEAD.docs">HEAD docs</a> <ul> <li><a href="#Example">Example</a></li>

@@ -866,7 +871,7 @@

<pre><code>$ curl -i -X OPTIONS 'http://127.0.0.1:9500/docs/test/' HTTP/1.1 200 OK Content-Length: 0 -Access-Control-Allow-Methods: HEAD,GET,OPTIONS +Access-Control-Allow-Methods: HEAD,GET,OPTIONS,POST Allow: HEAD,GET,OPTIONS Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: *

@@ -888,6 +893,23 @@ Access-Control-Allow-Origin: *

Server: LiteStore/1.0.3 {"id": "555f93e82190e77500000000", "data": "A document with a randomly-generated ID.", "created": "2015-05-22T08:39:04Z", "modified": null, "tags": ["$type:text", "$subtype:plain", "$format:text"]} +</code></pre> + +<h4 id="POST.docs.:folder.">POST docs/:folder/<a href="#document-top" title="Go to top"></a></h4> + +<p>Creates a new document with a randomly-generated ID under the specified folder path.</p> + +<h5 id="Example">Example<a href="#document-top" title="Go to top"></a></h5> + +<pre><code>$ curl -i -X POST -d 'A document with a randomly-generated ID.' 'http://127.0.0.1:9500/docs/test/' --header "Content-Type:text/plain" +HTTP/1.1 201 Created +Content-Length: 197 +Content-Type: application/json +Access-Control-Allow-Headers: Content-Type +Access-Control-Allow-Origin: * +Server: LiteStore/1.0.3 + +{"id": "test/555f93e82230f77500000000", "data": "A document with a randomly-generated ID.", "created": "2015-05-22T08:39:04Z", "modified": null, "tags": ["$type:text", "$subtype:plain", "$format:text"]} </code></pre> <h4 id="HEAD.docs">HEAD docs<a href="#document-top" title="Go to top"></a></h4>

@@ -948,7 +970,7 @@ <li><strong>search</strong> &ndash; Search for the specified string. Example: <code>http://127.0.0.1:9500/docs/?search=Something</code>.</li>

<li><strong>tags</strong> &ndash; Retrieve only documents with matching tag(s). Example: <code>http://127.0.0.1:9500/docs/?tags=tag1,tag2</code></li> <li><strong>limit</strong> &ndash; Retrieve only the first <em>n</em> results. Example: <code>http://127.0.0.1:9500/docs/?limit=5</code></li> <li><strong>offset</strong> &ndash; Skip the first <em>n</em> results. Example: <code>http://127.0.0.1:9500/docs/?offset=5</code></li> -<li><strong>sort</strong> &ndash; Sort by <strong>created</strong>, <strong>modified</strong>, or <strong>id</strong>. Example: <code>http://127.0.0.1:9500/docs/?sort=id</code></li> +<li><strong>sort</strong> &ndash; Sort by <strong>created</strong>, <strong>modified</strong>, and/or <strong>id</strong> (prepend <strong>-</strong> for DESC and <strong>+</strong> for ASC). Example: <code>http://127.0.0.1:9500/docs/?sort=-modified,-created</code></li> <li><strong>contents</strong> &ndash; If set to <strong>false</strong>, do not retrieve document data. Example: <code>http://127.0.0.1:9500/docs/?contents=false</code></li> </ul>

@@ -1176,7 +1198,7 @@ </ul>

</div> <div id="footer"> - <p><span class="copy"></span> Fabio Cevasco &ndash; April 17, 2016</p> + <p><span class="copy"></span> Fabio Cevasco &ndash; May 8, 2016</p> <p><span>Powered by</span> <a href="https://h3rald.com/hastyscribe"><span class="hastyscribe"></span></a></p> </div> </body>
M admin/md/api_docs.mdadmin/md/api_docs.md

@@ -177,7 +177,7 @@ * **search** &ndash; Search for the specified string. Example: `http://127.0.0.1:9500/docs/?search=Something`.

* **tags** &ndash; Retrieve only documents with matching tag(s). Example: `http://127.0.0.1:9500/docs/?tags=tag1,tag2` * **limit** &ndash; Retrieve only the first _n_ results. Example: `http://127.0.0.1:9500/docs/?limit=5` * **offset** &ndash; Skip the first _n_ results. Example: `http://127.0.0.1:9500/docs/?offset=5` -* **sort** &ndash; Sort by **created**, **modified**, or **id**. Example: `http://127.0.0.1:9500/docs/?sort=id` +* **sort** &ndash; Sort by **created**, **modified**, and/or **id** (prepend **-** for DESC and **+** for ASC). Example: `http://127.0.0.1:9500/docs/?sort=-modified,-created` * **contents** &ndash; If set to **false**, do not retrieve document data. Example: `http://127.0.0.1:9500/docs/?contents=false` > %tip%
M lib/api_v1.nimlib/api_v1.nim

@@ -18,15 +18,17 @@

# Helper procs -proc orderByClause(clause: string): string = - var matches = @["", ""] - if clause.find(peg"{[-+ ]} {(id / created / modified)}", matches) != -1: - if matches[0] == "-": - return "$1 DESC" % matches[1] - else: - return "$1 ASC" % matches[1] - else: - return "" +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 parseQueryOption(fragment: string, options: var QueryOptions) = var pair = fragment.split('=')

@@ -52,7 +54,7 @@ options.offset = pair[1].parseInt

except: raise newException(EInvalidRequest, "Invalid offset value: $1" % getCurrentExceptionMsg()) of "sort": - let orderby = pair[1].orderByClause() + let orderby = pair[1].orderByClauses() if orderby != "": options.orderby = orderby else:
M lib/api_v2.nimlib/api_v2.nim

@@ -18,15 +18,17 @@

# Helper procs -proc orderByClause(clause: string): string = - var matches = @["", ""] - if clause.find(peg"{[-+ ]} {(id / created / modified)}", matches) != -1: - if matches[0] == "-": - return "$1 DESC" % matches[1] - else: - return "$1 ASC" % matches[1] - else: - return "" +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 parseQueryOption(fragment: string, options: var QueryOptions) = var pair = fragment.split('=')

@@ -52,7 +54,7 @@ options.offset = pair[1].parseInt

except: raise newException(EInvalidRequest, "Invalid offset value: $1" % getCurrentExceptionMsg()) of "sort": - let orderby = pair[1].orderByClause() + let orderby = pair[1].orderByClauses() if orderby != "": options.orderby = orderby else: