Storage
You can use any existing storage adapter or write your own
Overview
Storage type | Description |
In-memory | Default storage that stores data in memory, that is reset after this process exits or tab is closed. Ideal for short living one-time bots or testing. It is not persistant. |
Persistant file-based key=value storage with `fs` | Simple storage that stores everything in memory and periodically syncs it with locally stored file in key=value format. `filePath` is optional and defaults to `./storage.db` |
Creating new storage adapter
To implement your own storage, write class that implements Storage interface from @session.js/types/storage
. Take a look at this example with in-memory storage
import type { Storage } from '@session.js/types'
export class MyInMemoryStorage implements Storage {
storage: Map<string, string> = new Map()
get(key: string) {
return this.storage.get(key) ?? null
}
set(key: string, value: string) {
this.storage.set(key, value)
}
delete(key: string) {
this.storage.delete(key)
}
has(key: string) {
return this.storage.has(key)
}
}