Crates.io | hoardbase |
lib.rs | hoardbase |
version | 0.1.0-alpha |
source | src |
created_at | 2021-12-20 20:30:49.614058 |
updated_at | 2021-12-20 20:30:49.614058 |
description | Hoardbase is a single-file embedded database based on sqlite with an API identical to that of mongodb. |
homepage | |
repository | |
max_upload_size | |
id | 500844 |
size | 158,077 |
Hoardbase is sqlite disguised as a NoSql database with an API similar to that of mongodb. There had been many times that I need a single-file embeded NoSql solution and couldn't find any. For my use cases, a good choice should meet the following requirements:
I feel that an embedable NoSql is a very common building block that lacks good choices. The cloest one, in my opinion, is ejdb2. However, that project is inactive and its code readability is poor. But what about this project? Sqlite is a solid fundation and has been battle tested. I try to keep my warpper layer simple and its internal well documented to make sure fixability.
Hoardbase tries to provide a similar programming interface as that of mongodb. If you are already familiar with mongodb, using Hoardbase should be very simple.
The key mechanism for storing and querying json data using sqlite is serializing json documents into the blob type. Currently [bson
] is used
as the serialized format. Another interesting format is Amazon Ion. I may add support for Ion in the future
when its rust binding matures.
Indexing and searching is implemented using sqlite's application-defined functions. Basically, we can define
custom functions that operates on the blob type to extract a json field, or patch a blob. As long as those custom functions are deterministic, they
can be used for indexing and searching. For example, we can define a function bson_field(path, blob)
that extracts a bson field from the blob.
If we invoke this function with WHERE bson_field('name.id', blob) = 3
against a collection, we will find all documents with name.id equals to 3. We can
also create indices on bson fields using this function. For more references, these are some good links: