Antispace KV

Antispace offers a data persistence layer for all apps deployed to the platform.
Antispace KV is a distributed high-performance key-value store that can be accessed via Antispace SDK.

Preparation

To use Antispace KV, you first need to optain a Platform Token in your App Developer settings.

Note: Platform Token is different from the CLI token, they are not interchangeable.

Setup

To use Antispace KV, first import it from the SDK and create a new instance.

Antispace KV Setup

import { KV } from "@antispace/sdk"

const kv = new KV()

export default kv

By default, Antispace SDK will look for the platform key in ANTISPACE_PLATFORM_TOKEN. Alternatively, you can pass the token as the first argument to the constructor:

const kv = new KV(yourPlatformToken)

Note: if you are not deploying your app to Antispace, using Antispace KV also requires ANTISPACE_APP_ID environment variable to be set. Alternatively, you can pass appId as the second argument to the KV constructor.

Usage

Once you set up your environment and created a KV instance, you can use it to persist and access your app's data with the following methods:

Using Antispace KV

// Get data
const someData = await kv.get('some-data')

// Set data
await kv.set('users:some-user', { name: 'John Antispacer', email: '[email protected]' })

// Update data
await kv.update('users:some-user', { email: '[email protected]' })

// Delete data
await kv.delete('users:some-user')

Note: The kv.update() method is upsert, if a key is not present - it will be created. However we recommend that you create key-value pairs with kv.set() for disambiguation and code readability.

Was this page helpful?