We like minimalism.
Offbase is an extension of the excellent nlohmann/json C++11 JSON class that adds simple object persistence to/from the filesystem. Objects are stored into a directory hierarchy in fully "expanded" form with each field/value being represented by a separate file.
Features:
find
and grep
, etc.git
, rsync
, duplicity
, etc..git
or .DS_Store
are harmlessly ignored if presentLimitations and shortcomings:
btrfs
or reiserfs
. Things like redisfs are also worth exploring. On Linux another alternative is to put the database into /dev/shm
(RAM disk) and then regularly back it up with duplicity
or similar.commit()
slow for huge data sets. This is not suitable for "big" data where "big" here is probably more than a few hundred megabytes.Caveats:
Future:
The offbase
class just extends nlohmann::json and gives you a JSON object. Take care to make sure you don't change the type of the 'root' object represented by the 'offbase' instance from JSON 'object'. Anything under it can of course be any JSON type, including any object.
Just put data into the object and then periodically call commit()
to persist changes to disk. The commit()
method diffs the current contents of the object with what it knows to have been previously persisted to disk and modifies the representation on disk to match. This can be done after writes or periodically in a background thread.
See comments in offbase.hpp
for full documentation including details about error handling, etc.
The base object represented by the offbase
instance is persisted into a directory hierarchy under its base path. Files and directories are named according to a simple convention of keyname.typecode
where keyname
is an escaped key name (or hex array index in the case of arrays) and typecode
is a single character indicating whether the item is a JSON value, array, or object.
*.V
: JSON values (actual value type is inferred during JSON parse)*.O
: JSON objects (these are subdirectories)*.A
: JSON arrays (also subdirectories containing items by hex array index)There are in theory simpler ways to represent JSON in a filesystem, such as the "flattened" JSON "pointer" format, but this has the disadvantage of not disambiguating objects vs. arrays. Offbase's persistence format is designed to perfectly reproduce the exact same JSON tree on load as was most recently committed.