RygelDB RygelDB is a NoSQL document store using commands to store and query documents!
What the Yotz?! - Dominar Rygel the XVI
- Usage
- Storing and Querying Data
- Defining Collections
- Removing Collections
- Storing Data
- Querying data
- Remove data
- Update data
- Where Predicates
Usage
Run go run .
or go build .
, as you like.
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
Creates a new collection where document items may be stored.
Removing Collections
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:
path
an array of keys, with each key being a step into a nested structure. The value for the last key is used in the comparison.operator
how the value is compared.value
what the value is expected to be to match.
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:
[{“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:
=
asserts if the value on path is equal to the expected value.!=
refutes if value on path is equal to the expected value.>
compares if value on path is greater than expected value.>=
compares if value on path is greater than or equal to the expected value.<
compares if value on path is less than the expected value.<=
compares if value on path is less than or equal to the expected value.
TODOs / Wishlist / Ideas
- Concurrency-safe with multiple connections
- Setup Dependency-Injection strcture for the application and tests
- Move away from writing entire store to a file on every change to a “ledger” based persistence.
- Document project architecture and implementation.
- Possible move project structure to the Standard Go-Lang Layout if it grows too much
- Add Snapshotting to Persistence Ledgers.
- Add Indices/quick key lookups for nested data structures.
- Allow SocketServer to be configurable (e.g. change port binding)
- Allow for concurrent Read Operations between connections
- Allow for concurrent Write Operations between connections
May your afterlife be almost as pleasant as mine. - Dominar Rygel the XVI