RygelDB.

RygelDB RygelDB is a NoSQL document store using commands to store and query documents!

What the Yotz?! - Dominar Rygel the XVI

Usage

Run go run . or go build ., as you like.

1$ go run .
2
3Starting tcp server on localhost:8080

You can connect using a socket once it has started like so:

1nc localhost 8080

Storing and Querying Data

Rygel stores JSON document items in collections.

All commands can be sent over socket. To test them individually, you may pipe time:

1echo '{ "operation": "DEFINE COLLECTION", "collection_name": "test_collection" }' | nc localhost 8080

Defining Collections

1{ 
2  "operation": "DEFINE COLLECTION",
3  "collection_name": "collection_name"
4}

Creates a new collection where document items may be stored.

Removing Collections

1{ 
2  "operation": "REMOVE COLLECTION",
3  "collection_name": "collection_name"
4}

Removes a collection from the datbase. This removes all stored JSON document items within it.

Storing Data

1{ 
2  "operation": "STORE",
3  "collection_name": "collection_name",
4  "data": {"data": "structure of document"}
5}

Stores a document item in a collection. Data can be any valid JSON structure.

Querying data

1{ 
2  "operation": "FETCH",
3  "collection_name": "collection_name",
4  "limit": 1,
5  "where": [
6    { "path": ["foo"], "operator": "=", "value": "new value" }
7  ]
8}

Queries for data in a collection. The limit parameter is optional and if provided, will stop looking for items after it has reached it’s limit.

Rygel can query for data based on certain criteria, named where predicates. Each where predicate is defined used:

Given the following data:

 1{
 2  "operation": "DEFINE COLLECTION",
 3  "collection_name": "fruits"
 4}
 5{ 
 6  "operation": "STORE",
 7  "collection_name": "fruits",
 8  "data": {"key":"apple","color":"red"}
 9}
10{ 
11  "operation": "STORE",
12  "collection_name": "fruits",
13  "data": {"key":"orange","color":"orange"}
14}

Querying for a single document would look like:

1{ 
2  "operation": "FETCH",
3  "collection_name": "fruits",
4  "limit": 1
5}

[{“color”:“orange”,“key”:“orange”}]

Querying for all documents that meet a criteria:

1{ 
2  "operation": "FETCH",
3  "collection_name": "fruits",
4  "where": [
5    { "path": ["color"], "operator": "=", "value": "red" },
6  ]
7}

[{“color”:“red”,“key”:“apple”}]

It’s possible to query based on deep properties and multiple WHERE clauses:

 1{ 
 2  "operation": "STORE",
 3  "collection_name": "fruits",
 4  "data": {
 5    "key": "dragonfruit",
 6    "color": "red",
 7    "properties": {
 8      "spikes": "many",
 9      "internal_color": "white"
10    }
11  }
12}
13{ 
14  "operation": "FETCH",
15  "collection_name": "fruits",
16  "where": [
17    { "path": ["color"], "operator": "=", "value": "red" },
18    { "path": ["properties", "internal_color"], "operator": "=", "value": "white" },
19  ]
20}

[{“color”:“red”,“key”:“dragonfruit”,“properties”:{“internal_color”:“white”,“spikes”:“many”}}]

Remove data

1{ 
2  "operation": "REMOVE ITEMS",
3  "collection_name": "test_collection",
4  "limit": 1,
5  "where": [
6    { "path": ["amount"], "operator": ">", "value": 1000 },
7  ]
8}

Removes JSON document items from a collection. Limit is optional.

Update data

1{ 
2  "operation": "UPDATE ITEM",
3  "collection_name": "test_collection",
4  "limit": 1,
5  "where": [
6    { "path": ["foo"], "operator": "=", "value": "bar" }
7  ],
8  "data": {"foo": "YOTZ!"}
9}

Updates JSON items in a collection. Works with where predicates and limit is optional.

Note, this command replaces the data structure and is not an deep merge of the two data objects.

Where Predicates

Where predicates can compare strings, integers, and booleans.

They provide a number of different operators useful for these value types:

TODOs / Wishlist / Ideas


May your afterlife be almost as pleasant as mine. - Dominar Rygel the XVI