Using the Key-Value DB

The key-value storage in W3bstream is specifically designed for storing data that can be retrieved using a unique key. This functionality proves useful for various purposes, such as storing application settings and maintaining status information.

To store an object called "myObj" in the key-value database, a W3bstream applet can utilize the SetDB function.

The example below demonstrates how you can store and retrieve an integer value from the key-value storage:

import { GetDB, SetDB } from "@w3bstream/wasm-sdk";
export { alloc } from "@w3bstream/wasm-sdk";

export function my_habdler(rid: i32): i32 {
  // Read the data stored under the key "users_count"
  let value = GetDB("users_count");
  // Convert the string to i32
  let users_count = value ? parseInt(value) : 0;
  // store the new value
  let result = SetDB("users_count", (i32(users_count) + 1));

  return 0;

Last updated