1
0

Support for store.has syscall

This commit is contained in:
Zef Hemel 2023-01-26 15:26:56 +01:00
parent bc8d2d5e61
commit d133c79de0
3 changed files with 12 additions and 0 deletions

View File

@ -31,6 +31,10 @@ export function get(key: string): Promise<any> {
return syscall("store.get", key);
}
export function has(key: string): Promise<boolean> {
return syscall("store.has", key);
}
export function del(key: string): Promise<void> {
return syscall("store.delete", key);
}

View File

@ -135,6 +135,13 @@ export function storeSyscalls(
return null;
}
},
"store.has": async (_ctx, key: string): Promise<boolean> => {
const result = await db.query(
`SELECT count(value) as cnt FROM ${tableName} WHERE key = ?`,
key,
);
return result[0].cnt === 1;
},
"store.queryPrefix": async (_ctx, prefix: string) => {
return (
await db.query(

View File

@ -7,6 +7,7 @@ export function storeSyscalls(space: Space): SysCallMapping {
[
"store.queryPrefix",
"store.get",
"store.has",
"store.set",
"store.batchSet",
"store.delete",