Key-value Data Store
Data in a key-value data store is stored and retrieved using a key that uniquely identifies the record.
API
The data storage API is available in WebApps and RESTApps.
js
// retrieve an instance of the storage API
import storage from '@sitevision/api/server/storage';
// get a key-value store
// if no store exists with the provided name, one will be created
// (note: the name must also be explicitly registered in the app's manifest.json)
const keyValueStore = storage.getKeyValueDataStore('myStore');
put(key, data) [@since 5.2]
Stores data associated with a key.
Returns current data stored on the key.
Argument | Description |
|---|---|
| A key to uniquely identify the record |
| JSON data to store |
const config = {
name: 'Foo',
title: 'Bar'
};
try {
keyValueStore.put('config', config);
} catch (e) {
// [Error handling](https://developer.sitevision.se/docs/data-storage/error-handling)
}
If a property is set to null, the property will be removed
get(key) [@since 5.2]
Returns data associated with a key.
Argument | Description |
|---|---|
| A key to retrieve data from |
try {
config = keyValueStore.get('config');
} catch (e) {
// [Error handling](https://developer.sitevision.se/docs/data-storage/error-handling)
}
remove(key) [@since 5.2]
Removes data associated with a key.
Returns the removed data.
Argument | Description |
|---|---|
| A key to identify data to remove |
try {
keyValueStore.remove('config');
} catch (e) {
// [Error handling](https://developer.sitevision.se/docs/data-storage/error-handling)
}
Did you find the content on this page useful?