cortoproject / driver-mnt-filestore

Store and retrieve objects in/from JSON files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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());
}

About

Store and retrieve objects in/from JSON files

License:MIT License


Languages

Language:C 100.0%