core: db upd

This commit is contained in:
undefined committed 2020-12-19 01:33:23 +08:00
1 parent e7794090b2
commit fc3321688f
4 files changed
+89 -40

No files matched your search

+6 -2
View File
@@ -7,7 +7,9 @@ import * as bus from '../service/bus';
const coll = db.collection('system');
const cache: Record<string, any> = {};
export function get<K extends keyof SystemKeys>(key: K): SystemKeys[K] {
export function get<K extends keyof SystemKeys>(key: K): SystemKeys[K]
export function get(key: string): any
export function get(key: string): any {
return cache[key];
}
@@ -34,7 +36,9 @@ export function getMany(keys: string[]): any[] {
return keys.map((key) => cache[key]);
}
export async function set<K extends keyof SystemKeys>(_id: K, value: SystemKeys[K]) {
export async function set<K extends keyof SystemKeys>(_id: K, value: SystemKeys[K]): Promise<SystemKeys[K]>
export async function set<K>(_id: string, value: K): Promise<K>
export async function set(_id: string, value: any) {
const res = await coll.findOneAndUpdate(
{ _id },
{ $set: { value } },