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