1
0
silverbullet/syscall/plugos-syscall/store.ts

55 lines
1.1 KiB
TypeScript
Raw Normal View History

import { syscall } from "./syscall.ts";
2022-04-01 15:07:08 +00:00
export type KV = {
key: string;
value: any;
};
export type Query = {
filter?: Filter[];
orderBy?: string;
orderDesc?: boolean;
limit?: number;
select?: string[];
};
export type Filter = {
op: string;
prop: string;
value: any;
};
export function set(key: string, value: any): Promise<void> {
2022-04-01 15:07:08 +00:00
return syscall("store.set", key, value);
}
export function batchSet(kvs: KV[]): Promise<void> {
2022-04-01 15:07:08 +00:00
return syscall("store.batchSet", kvs);
}
export function get(key: string): Promise<any> {
2022-04-01 15:07:08 +00:00
return syscall("store.get", key);
}
export function del(key: string): Promise<void> {
2022-04-01 15:07:08 +00:00
return syscall("store.delete", key);
}
export function batchDel(keys: string[]): Promise<void> {
2022-04-01 15:07:08 +00:00
return syscall("store.batchDelete", keys);
}
export function queryPrefix(
prefix: string,
2022-04-01 15:07:08 +00:00
): Promise<{ key: string; value: any }[]> {
return syscall("store.queryPrefix", prefix);
}
export function deletePrefix(prefix: string): Promise<void> {
2022-04-01 15:07:08 +00:00
return syscall("store.deletePrefix", prefix);
}
export function deleteAll(): Promise<void> {
2022-04-01 15:07:08 +00:00
return syscall("store.deleteAll");
}