egg_server/db/appInfo/index.ts
zhaoyingbo 490c6ea3e5
All checks were successful
Egg CI/CD / build-image (push) Successful in 29s
Egg CI/CD / deploy (push) Successful in 21s
feat: 优化app数据的存储方式
2024-07-10 11:26:56 +00:00

40 lines
758 B
TypeScript

import pbClient from "../pbClient";
import { managePb404 } from "../../utils/pbTools";
import { DB } from "../../types";
/**
* 获取配置
* @param appName
* @returns
*/
const get = async (appName: string) =>
managePb404<DB.AppInfo>(() =>
pbClient.collection("app_info").getFirstListItem(`code_name='${appName}'`)
);
/**
* 获取所有配置
* @returns
*/
const getFullList = () => pbClient.collection("app_info").getFullList();
/**
* 获取配置的某个值
* @param appName
* @param key
* @returns
*/
const getVal = async (appName: string, key: string) => {
const config = await get(appName);
if (!config) return "";
return config[key] || "";
};
const appInfo = {
get,
getVal,
getFullList,
};
export default appInfo;