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

   app.js

  • await client.db.set(key, value) can be used to set a key-value pair for a user.
  await client.db.set("data", newData);

   server.js

  • await $Storage.set(key, value) can be used to set a key-value pair from the server side code of the app.
  await $Storage.set("data", newData);
  • Retrive

   app.js

  • const result = await client.db.get(key) can be used to retrieve a value for that particular user. It returns a stringified object which can be then converted to json by JSON.parse(result).
  const result = JSON.parse(await window.client.db.get("data"));

   server.js

  • const result = await $Storage.get(key) can be used to retrieve a value for that particular key for that particular user from the server side code of your app.
const result = await $Storage.get("data");