/driver-mnt-filestore

Store and retrieve objects in/from JSON files

Primary LanguageCMIT LicenseMIT

filestore

Store and retrieve objects in/from JSON files

Usage

The easiest way to add a filestore to your project is to add a configuration file to your project and then load this file with ut_use in your application. Here's an example that recursively persists all objects under /data, and stores the files in /tmp/myProjectStore:

filestore.json:

{
  "type": "driver/mnt/filestore/mount",
  "value": {
    "storedir": "/tmp/myProjectStore",
    "query": {
      "select": "//",
      "from": "data"
    },
    "policy.ownership": "LOCAL_SOURCE"
  }
}

By setting policy.ownership to LOCAL_SOURCE, objects in the store will be owned by the application. This ensures that when you restart the application, initial values from persisted objects are overwritten with the latest value from the store.

You can load this file in your application, by doing:

if (ut_use("filestore.json", 0, NULL)) {
    ut_error("%s", ut_lasterr());
}