all repos — litestore @ 98a52155446efe3062f71ef0a0b45a577ad365e6

A minimalist nosql document store.

Updated docs.
h3rald h3rald@h3rald.com
Mon, 13 Jan 2020 14:30:14 +0100
commit

98a52155446efe3062f71ef0a0b45a577ad365e6

parent

aa96542a6a02be9e968255edbeee4c8e18e37059

M src/admin/js/components/navbar.jssrc/admin/js/components/navbar.js

@@ -24,6 +24,7 @@ {path: "/guide/api_info", title: caret+"info (LiteStore Information)"},

{path: "/guide/api_dir", title: caret+"dir (LiteStore Directory)"}, {path: "/guide/api_docs", title: caret+"docs (LiteStore Documents)"}, {path: "/guide/api_tags", title: caret+"tags (LiteStore Tags)"}, + {path: "/guide/api_indexes", title: caret+"indexes (LiteStore Indexes)"}, {path: "/guide/credits", title: "Credits"} ]; vm.taglinks = function(info){
M src/admin/md/api_docs.mdsrc/admin/md/api_docs.md

@@ -232,6 +232,7 @@ Examples:

* 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" +* http://127.0.0.1:9500/docs/?filter=$.name.first&20like%20"J*" ##### `select` option

@@ -556,4 +557,4 @@ Content-Length: 0

Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: * Server: LiteStore/1.0.3 -``` +```
A src/admin/md/api_indexes.md

@@ -0,0 +1,154 @@

+### indexes (LiteStore Indexes) + +> %note% +> API v5 Required +> +> This resource has been introduced in version 5 of the LiteStore API. + +LiteStore Indexes are special indexes used to optimize the performance of queries on JSON documents. + +> %warning% +> JSON-only Documents Required! +> +> Indexes can be created *only* if the entire database is composed by JSON documents. If not, LiteStore will return an error when attempting to create the first index. + +#### OPTIONS indexes + +Returns the allowed HTTP verbs for this resource. + +##### Example + +``` +$ curl -i -X OPTIONS http://127.0.0.1:9500/indexes +HTTP/1.1 200 OK +server: LiteStore/1.7.0 +access-control-allow-origin: http://localhost:9500 +access-control-allow-headers: Content-Type +allow: GET,OPTIONS +access-control-allow-methods: GET,OPTIONS +content-length: 0 +``` + +#### OPTIONS indexes/:id + +Returns the allowed HTTP verbs for this resource. + +##### Example + +``` +$ curl -i -X OPTIONS http://127.0.0.1:9500/indexes/name +HTTP/1.1 200 OK +server: LiteStore/1.7.0 +access-control-allow-origin: http://localhost:9500 +access-control-allow-headers: Content-Type +allow: GET,OPTIONS,PUT,DELETE +access-control-allow-methods: GET,OPTIONS,PUT,DELETE +Content-Length: 0 +``` + +#### GET indexes + +Retrieves all indexes and their respective JSON fields. + +##### `like` option + +If this option is specified, retrieves all indexes matching the specified string. + +> %tip% +> Wildcards +> +> You can use asterisks (\*) as wildcards. + +##### `limit` and `offset` options + +Provide a way to implement pagination: + +* **limit** causes the query to retrieve only the first _n_ results. +* **offset** causes the query to skip the first _n_ results. + +##### Example + +``` +$ curl -i http://localhost:9500/indexes/?like=%2Aname%2A +HTTP/1.1 200 OK +server: LiteStore/1.7.0 +access-control-allow-origin: http://localhost:9500 +content-type: application/json +vary: Origin +access-control-allow-headers: Content-Type +Content-Length: 244 + +{ + "like": "*name*", + "total": 2, + "execution_time": 0.0006140000000000001, + "results": [ + { + "id": "name", + "field": "$.name" + }, + { + "id": "document.name", + "field": "$.document.name" + } + ] +} +``` + +#### GET index/:id + +Retrieves the specified index and corresponding JSON field. + +##### Example + +``` +$ curl -i http://localhost:9500/indexes/name +HTTP/1.1 200 OK +server: LiteStore/1.7.0 +access-control-allow-origin: http://localhost:9500 +content-type: application/json +vary: Origin +access-control-allow-headers: Content-Type +Content-Length: 30 + +{"id":"name","field":"$.name"} +``` + +#### PUT indexes/:id + +Creates a new index with the specified ID. + +> %warning% +> No updates +> +> It is not possible to update an existing index. Delete it and re-create it instead. + + +##### Example + +``` +$ curl -i -X PUT -d '{"field": "$.name"}' 'http://127.0.0.1:9500/indexes/name' --header "Content-Type:application/json" +HTTP/1.1 201 Created +Content-Length: 31 +Content-Type: application/json +Access-Control-Allow-Headers: Content-Type +Access-Control-Allow-Origin: http://localhost:9500 +Server: LiteStore/1.7.0 + +{"id":"name", "field":"$.name"} +``` + +#### DELETE indexes/:id + +Deletes the specified index. + +##### Example + +``` +$ curl -i -X DELETE 'http://127.0.0.1:9500/indexes/name' +HTTP/1.1 204 No Content +Content-Length: 0 +Access-Control-Allow-Headers: Content-Type +Access-Control-Allow-Origin: http://localhost:9500 +Server: LiteStore/1.7.0 +```
M src/admin/md/api_tags.mdsrc/admin/md/api_tags.md

@@ -54,6 +54,13 @@ > Wildcards

> > You can use asterisks (\*) as wildcards. +##### `limit` and `offset` options + +Provide a way to implement pagination: + +* **limit** causes the query to retrieve only the first _n_ results. +* **offset** causes the query to skip the first _n_ results. + ##### Example ```

@@ -104,4 +111,4 @@ access-control-allow-headers: Content-Type

Content-Length: 34 {"id":"$type:text","documents":32} -``` +```
M src/admin/md/overview.mdsrc/admin/md/overview.md

@@ -27,7 +27,7 @@ #### Document Tagging

You can add custom tags to documents to easily categorize them and retrieve them. Some system tags are also added automatically to identify the document content type, format and collection. -#### Enhanced Querying of JSON documents +#### Enhanced Querying and Indexing of JSON documents By leveraging the [SQLite JSON1 extension](https://www.sqlite.org/json1.html) and implementing custom query string parsing, LiteStore provides enhanced filtering, ordering, and custom field selection of JSON documents.

@@ -39,6 +39,10 @@ #### RESTful HTTP API

Every operation can be performed on the data store using a simple but powerful RESTful HTTP API, perfect for client-side, single-page applications. +#### Authorization + +Optionally, you can configure per-resource authorization by validating [JWT](https://jwt.io/) tokens and checking [Oauth2 Scopes](https://oauth.net/2/scope/) + #### Nim API If you want, you can use LiteStore as a [Nim](https://nim-lang.org) library and perform data store operations from your own Nim program.

@@ -53,4 +57,4 @@ To make serving a single-page application _from LiteStore_ even easier and faster, you can automatically import (and export) the contents of a directory recursively.

#### Directory Mounting and Mirroring -After importing the contents of a directory into a LiteStore data store, you can _mount it_ on LiteStore and mirror all data store changes to the filesystem. Incidentally, that's how most of the LiteStore Admin test app was built [](class:fa-smile-o). +After importing the contents of a directory into a LiteStore data store, you can _mount it_ on LiteStore and mirror all data store changes to the filesystem. Incidentally, that's how most of the LiteStore Admin test app was built [](class:fa-smile-o).
M src/litestorepkg/lib/api_v5.nimsrc/litestorepkg/lib/api_v5.nim

@@ -663,6 +663,33 @@ result.headers = newHttpHeaders(TAB_HEADERS)

setOrigin(LS, req, result.headers) result.headers["Allow"] = "GET, OPTIONS" result.headers["Access-Control-Allow-Methods"] = "GET, OPTIONS" + of "indexes": + result.code = Http204 + result.content = "" + result.headers = newHttpHeaders(TAB_HEADERS) + setOrigin(LS, req, result.headers) + if id != "": + result.code = Http204 + result.content = "" + if LS.readonly: + result.headers["Allow"] = "GET, OPTIONS" + result.headers["Access-Control-Allow-Methods"] = "GET, OPTIONS" + else: + result.headers["Allow"] = "GET, OPTIONS, PUT, DELETE" + result.headers["Access-Control-Allow-Methods"] = "GET, OPTIONS, PUT, DELETE" + else: + result.code = Http204 + result.content = "" + if LS.readonly: + result.headers = newHttpHeaders(TAB_HEADERS) + setOrigin(LS, req, result.headers) + result.headers["Allow"] = "GET, OPTIONS" + result.headers["Access-Control-Allow-Methods"] = "GET, OPTIONS" + else: + result.headers = newHttpHeaders(TAB_HEADERS) + setOrigin(LS, req, result.headers) + result.headers["Allow"] = "GET, OPTIONS" + result.headers["Access-Control-Allow-Methods"] = "GET, OPTIONS" of "docs": var folder: string if id.isFolder:
M src/litestorepkg/lib/config.nimsrc/litestorepkg/lib/config.nim

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

const pkgName* = "litestore" - pkgVersion* = "1.6.0" + pkgVersion* = "1.7.0" pkgAuthor* = "Fabio Cevasco" pkgDescription* = "Self-contained, lightweight, RESTful document store." pkgLicense* = "MIT"