Classcorev0.14.0
class KvCollection<TRecord>interface Profile { bio: string; joinedAt: Date }
const profiles = this.core.kv.collection<Profile>('profile');
await profiles.set(user.id, { bio: 'hi', joinedAt: new Date() });
const profile = await profiles.get(user.id); // { bio: string; joinedAt: string } | undefined
await profiles.delete(user.id);Member visibility
Filter class members by access level.
TRecord
TRecordpublic entries(): AsyncIterable<
[id: string, record: Stored<TRecord>]
>Throws:
A SeedcordError when the backend can't list its keys, like @keyv/memcache.
// schedules every saved reminder again after a restart
for await (const [id, reminder] of reminders.entries()) schedule(id, reminder);Stores what next returns for the record under id, then resolves to that value. next gets
the current record, or undefined when there is none.
Use it over a get() then a set() when two calls can change one record at the same time.
set(), delete(), and update() calls on one id run one after the other in this process.
None of them loses another's change. Two processes sharing one backend can still both read
before either writes.
Parameter:
ttlMsHow many milliseconds the stored record lasts. Pass a function to work it out from the record. Leave it out to keep the record until you delete it.
// counts a run of the command and resolves to the new count
const runs = await counts.update(user.id, (count) => (count ?? 0) + 1);