Key-value Store

Store is a fast key-value store perfect for storing small amounts of data.

  • Store data is persisted between wish executions
  • Store names need to be unique in your team
  • Stores are can be accessed from all wishes within your team

Key and store names

Both store names and keys can only contain letters, numbers, underscores and dashes. They must start with a letter and cannot end with a symbol.

Example valid keys are:

key my_table2 my-data-234 myCoolTable

Invalid keys:

contains spaces, endsinsymbol_ #invalidsymbol

Values

Values can be anything as long as it’s JSON serializable.

Example

export default async function (req, context) {
  // get a store by name
  const db = context.store("mystore");

  console.log(await db.set("key", "value")); // true
  console.log(await db.get("key")); // "value"
  console.log(await db.keys()); // [ "key" ]
  console.log(await db.delete("key")); // true
}

Store Methods

get

Static get(key: string, defaultValue: any): Promise<any>

Get a value from the storage.

Returns a promise that will resolve to the value under the key, if the key doesn’t exist it will resolve to the default value, if the default value is not provided, null will be returned.


set

Static set(key: string, value: any): Promise<boolean>

Set a value in the storage.


keys

Static keys(): Promise<string[]>

delete

Static delete(key: string): Promise

update

Static update(key, fun): Promise<boolean>

Get and set a value in a single call.

example

Increment a value.

db.update("key", (value) => {
  return value + 1;
})