Skip to content

deltavi/luppolo-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

luppoloDB LuppoloDB Build Status

In-memory Key-Value store.

Table of Contents

HTTP DBs API

GET LIST/EXPORT/PERSIST/RESTORE/DELETE all DBs

GET http://localhost:3003/luppolo/dbs?{action}

Description action
Get list of databases
Exports all the DBs data as JSON _export
Save all the DBs data on the file system _persist
Restore all the DBs data from the file system _restore
Delete all the DBs from the memory and from the file system _deleteAndPersist

Examples

Get list of database:
//[GET] "http://localhost:3003/luppolo/dbs"
{
    "result": "found",
    "db": "_all",
    "names": [
        "db1"
    ],
    "total": 1
}
Exports all the DBs data as JSON
//[GET] "http://localhost:3003/luppolo/dbs?_export"
{
    "result": "found",
    "db": "_all",
    "value": {
        "db1": {
            "1": {
                "value": {
                    "boolean": true,
                    "number": 123,
                    "string": "text",
                    "array": [
                        "123",
                        "456"
                    ]
                },
                "lastUpdate": "2018-07-14T09:01:01.748Z"
            }
        }
    }
}
Save all the DBs data on the file system
//[GET] "http://localhost:3003/luppolo/dbs?_persist"
{
  "result": "saved",
  "db": "_all"
}

on Error

{
  "result": "error",
  "db": "_all",
  "error": {
    "errno": -4048,
    "code": "EPERM",
    "syscall": "open",
    "path": "/luppolo-db/dump/dbs.json"
  }
}
Restore all the DBs data from the file system:
//[GET] "http://localhost:3003/luppolo/dbs?_restore"
{
  "result": "restored",
  "db": "_all"
}

on Error

{
  "result": "error",
  "db": "_all",
  "error": {
    "errno": -4058,
    "code": "ENOENT",
    "syscall": "open",
    "path": "/luppolo-db/dump/dbs.json"
  }
}
Delete all the DBs from the memory and from the file system:
//[GET] "http://localhost:3003/luppolo/dbs?_deleteAndPersist"
{
  "result": "deleted",
  "db": "_all"
}

on Error

{
  "result": "error",
  "db": "_all",
  "error": {
    "errno": -4048,
    "code": "EPERM",
    "syscall": "open",
    "path": "/luppolo-db/dump/dbs.json"
  }
}

HTTP DB API

PUT

Store or update a value in storage.

PUT http://localhost:3003/luppolo/db/db1/1

Body:

{
    "boolean": true,
    "number": 123,
    "string": "text",
    "array": [
        "123",
        "456"
    ]
}

Result:

{
    "result": "created",
    "db": "db1",
    "key": "1"
}

or

{
    "result": "updated",
    "db": "db1",
    "key": "1"
}

GET

Retrieve a value from storage.

GET http://localhost:3003/luppolo/db/db1/1

Result:

{
    "result": "found",
    "db": "db1",
    "key": "1",
    "value": {
        "boolean": true,
        "number": 123,
        "string": "text",
        "array": [
            "123",
            "456"
        ]
    },
    "lastUpdate": "2017-12-23T23:52:11.445Z"
}

or

{
    "result": "unknown",
    "db": "db1",
    "key": "1"
}

DELETE DB

Removes a DB from storage.

DELETE http://localhost:3003/luppolo/db/db1

Result:

{
    "result": "deleted",
    "db": "db1"
}

or

{
    "result": "unknown",
    "db": "db1"
}

DELETE

Removes a value from storage.

DELETE http://localhost:3003/luppolo/db/db1/1

Result:

{
    "result": "deleted",
    "db": "db1",
    "key": "1",
    "value": {
        "boolean": true,
        "number": 123,
        "string": "text",
        "array": [
            "123",
            "456"
        ]
    },
    "lastUpdate": "2017-12-23T23:56:38.310Z"
}

or

{
    "result": "unknown",
    "db": "db1",
    "key": "1"
}

GET DB KEYS

Retrieve a DB keys from storage.

GET http://localhost:3003/luppolo/db/db1

Result:

{
    "result": "found",
    "db": "db1",
    "keys": [
        "1"
    ],
    "total": 1
}

or

{
    "result": "unknown",
    "db": "db1",
    "total": 0,
    "keys": []
}

COUNT DB KEYS

GET http://localhost:3003/luppolo/db/db1?_count

Result:

{
    "result": "found",
    "db": "db1",
    "total": 1
}

or

{
    "result": "unknown",
    "db": "db1",
    "total": 0
}

SEARCH BY JSONPATH

It allows to search in the selected DB using jsonpath.

POST http://localhost:3003/luppolo/db/db1/_search

Body:

{
    "jpath" : "$..array"
}

Result:

{
    "result": "found",
    "db": "db1",
    "hits": [
        [
            "123",
            "456"
        ]
    ],
    "total": 1
}

SEARCH BY JSONPATH (NODES)

It allows to search in the selected DB using jsonpath, returning path and value of the nodes found.

POST http://localhost:3003/luppolo/db/db1/_search

Body:

{
    "jpath-nodes" : "$..array[?(@>200)]"
}

Result:

{
    "result": "found",
    "db": "db1",
    "hits": [
        {
            "path": ["$", "1", "value", "array", 1],
            "value": "456"
        }
    ],
    "total": 1
}

NUMERIC INCREMENT

Increments or decrement the number stored at key by incNumber.

PUT http://localhost:3003/luppolo/db/db1/1/_increment

PUT http://localhost:3003/luppolo/db/db1/1/_increment/100

PUT http://localhost:3003/luppolo/db/db1/1/_increment/-10

/{db}/{key}/_increment/{incNumber?}

Param Description Default
db DB name
key Key
incNumber Increment number +1

Result:

{
    "result": "created",
    "db": "db1",
    "key": "1",
    "value": 1
}

or

{
    "result": "updated",
    "db": "db1",
    "key": "1",
    "value": 2
}

or

{
    "result": "error",
    "db": "db1",
    "key": "1",
    "value": {
        "boolean": true,
        "number": 123,
        "string": "text",
        "array": [
            "123",
            "456"
        ]
    },
    "message": "value is NaN."
}

or

{
    "result": "error",
    "db": "db1",
    "key": "1",
    "value": 8,
    "message": "incNumber is NaN."
}