SDK for communicating between a Koji template and its in-built database service.
Each Koji project includes a key-value store that you can use as a backend database for simple use cases, such as collecting information from users, aggregating survey or poll results, and creating leaderboards for games.
The @withkoji/database package enables you to implement a Koji database for the backend of your template.
Install the package in the backend service of your Koji project.
npm install --save @withkoji/database
NOTE: To support instant remixes of your template, you must also install the @withkoji/vcc package and implement the VccMiddleware
on your backend server. This middleware maintains the environment variables for instant remixes, ensuring that database access is restricted to the correct remix version.
Import and instantiate the database SDK in the backend service.
import Database from '@withkoji/Database';
const database = new Database({
projectId: res.locals.KOJI_PROJECT_ID,
projectToken: res.locals.KOJI_PROJECT_TOKEN,
});
Set database entries in the database using the SDK.
const isAdded = await database.set('myCollection', 'myKey', {'myValue':1});
Get database entries from the database using the SDK.
const myEntry = await database.get('myCollection','myKey');
See the contributions page on the developer site for info on how to make contributions to Koji repositories and developer documentation.
For any questions, reach out to the developer community or the @Koji Team
on our Discord server.