Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Data Storage

Some apps need to store and retrieve data. For example apps like Power BI needs to store mapping details of each user. To achieve this we have key - value data storage where the data of the users are stored as a key-value pair and can also be retrieved.

For this tutorial let say we have an object:

const newData = {
    id: 123,
    name: "john doe"
  }

Store

set can be used to set a key-value pair for every installed user for the app.

app.js:

  await client.db.set("data", newData);

server.js:

  await $Storage.set("data", newData);

Retrieve

get can be used to retrieve a value for that particular installed user. It returns a stringified object which can be then converted to json by JSON.parse(result).

app.js:

  const result = JSON.parse(await window.client.db.get("data"));

server.js:

const result = await $Storage.get("data");

Handling Errors

  • Data storage methods directly return an Error object if any error occurs. So, it’s not required to handle the error in the try-catch block.

  • Each key-value pair has a maximum size limit of 250kb. Please ensure that data is stored within this constraint.