Logotype Sitevision Developer
Log in
Log in

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, RESTApps, Widgets and MCP Servers.

Example of how to get a datastore from any server-side JS-file
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');

API variants [@since 5.2]

The data storage API is available in two variants. One is callback-based whereas the other is callback-free. Please note that both variants execute synchronously, which probably makes the callback-free approach easier to work with.

put(key, data) [@since 5.2]

Stores data associated with a key.
Returns current data stored on the key.

Argument

Description

key

A key to uniquely identify the record

data

JSON data to store

keyValueStore.put example
js
const config = { name: 'Foo', title: 'Bar' }; try { keyValueStore.put('config', config); } catch (e) { // Error handling, see 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

key

A key to retrieve data from

keyValueStore.get example
js
try { config = keyValueStore.get('config'); } catch (e) { // Error handling, see 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

key

A key to identify data to remove

keyValueStore.remove
js
try { keyValueStore.remove('config'); } catch (e) { // Error handling, see https://developer.sitevision.se/docs/data-storage/error-handling }
Did you find the content on this page useful?