Persistent Unify Datastore.
More...
Persistent Unify Datastore.
Persistent datastore, that allows for storing key-value pair. The users of this component must handle updating own values if format change between versions. Keys are zero terminated strings
◆ datastore_key_t
◆ datastore_commit_transaction()
commit an open transaction
- Returns
- sl_status_t SL_STATUS_OK for success SL_STATUS_FAIL if an error occurred
◆ datastore_contains_arr()
Check if the datastore contains an array value for given key.
- Parameters
-
key | Key to check if is in the datastore |
- Returns
- true if key is present in the datatore else false
◆ datastore_contains_int()
Check if the datastore contains an int value for given key.
- Parameters
-
key | Key to check if is in the datastore |
- Returns
- true if key is present in the datatore else false
◆ datastore_fetch_arr()
Fetch array from the persistent datastore.
- Parameters
-
key | Key to fetch value under |
value | Destination for the key |
size | In: the size of value, Out: Number of bytes written to value |
- Returns
- sl_status_t SL_STATUS_OK if successful, SL_STATUS_NOT_FOUND if key is not found, SL_STATUS_WOULD_OVERFLOW if fetched data is larger than size SL_STATUS_FAIL if other failure,
◆ datastore_fetch_int()
Fetch integer from the persistent datastore.
- Parameters
-
key | Key to fetch value under |
value | Destination for the key |
- Returns
- sl_status_t SL_STATUS_OK if successful, SL_STATUS_NOT_FOUND if key is not found, SL_STATUS_FAIL if other failure,
◆ datastore_init()
sl_status_t datastore_init |
( |
const char * |
database_path | ) |
|
Initialize the Datastore component.
If the datastore init fails, then there is no reason to call datastore_teardown() If it initialized successful, then datastore_teardown() shall be called before exiting
- Parameters
-
database_path | Path to the database file, The directory the path must exist, or init will fail (or ":memory:" to use in memory database) |
- Returns
- sl_status_t SL_STATUS_OK for success SL_STATUS_FAIL if an error occurred
◆ datastore_is_initialized()
bool datastore_is_initialized |
( |
| ) |
|
Checks if the datastore is initialized and can be used.
- Returns
- true if the datastore can be used
-
false if the datastore cannot be used.
◆ datastore_start_transaction()
start a datastore transaction
With transactions, datastore calls will be cached so that they can be commited in one go. This increases the throughput of data. Only one transaction at the time can be open, otherwise SL_STATUS_ABORT
is returned.
- Returns
- sl_status_t SL_STATUS_OK for success SL_STATUS_IN_PROGRESS if there is an ongoing transaction SL_STATUS_FAIL if an error occurred
◆ datastore_store_arr()
Store array in the persistent datastore.
NOTE: If a record already exists for the given key, the stored value will be overwritten by the value provided.
NOTE: If casting larger data types into the array, the component doing this shall be able to handle different endianess, as because of back-up/restore it shall be supported to move the database from Big Endian to Little Endian and vice versa. For uint8_t arrays there are no issues, as they are unaffected by endianess
- Parameters
-
key | Key to store value under, must be unique |
value | Value to store under key |
size | Size of value array |
- Returns
- sl_status_t SL_STATUS_OK if successful, SL_STATUS_FAIL if failure
◆ datastore_store_int()
Store integer in the persistent datastore.
- Parameters
-
key | Key to store value under, must be unique |
value | Value to store under key |
- Returns
- sl_status_t SL_STATUS_OK if successful, SL_STATUS_FAIL if failure
◆ datastore_teardown()
Tear down the Datastore component.
Shall be called before exiting the application to close database file
- Returns
- sl_status_t SL_STATUS_OK for success, SL_STATUS_ERROR for failure