1
0

Add some datastore shortcuts

This commit is contained in:
Zef Hemel 2024-01-13 18:12:48 +01:00
parent 291280b709
commit 0ff005a595

View File

@ -23,6 +23,9 @@ export class DataStore {
} }
batchGet<T = any>(keys: KvKey[]): Promise<(T | null)[]> { batchGet<T = any>(keys: KvKey[]): Promise<(T | null)[]> {
if (keys.length === 0) {
return Promise.resolve([]);
}
return this.kv.batchGet(keys); return this.kv.batchGet(keys);
} }
@ -31,6 +34,9 @@ export class DataStore {
} }
batchSet<T = any>(entries: KV<T>[]): Promise<void> { batchSet<T = any>(entries: KV<T>[]): Promise<void> {
if (entries.length === 0) {
return Promise.resolve();
}
const allKeyStrings = new Set<string>(); const allKeyStrings = new Set<string>();
const uniqueEntries: KV[] = []; const uniqueEntries: KV[] = [];
for (const { key, value } of entries) { for (const { key, value } of entries) {
@ -50,6 +56,9 @@ export class DataStore {
} }
batchDelete(keys: KvKey[]): Promise<void> { batchDelete(keys: KvKey[]): Promise<void> {
if (keys.length === 0) {
return Promise.resolve();
}
return this.kv.batchDelete(keys); return this.kv.batchDelete(keys);
} }