feat: 封装增删查改函数

This commit is contained in:
eric
2022-11-13 18:25:18 +08:00
parent d71bf4dde6
commit 3ea7b3dfd8
16 changed files with 157 additions and 31 deletions

63
src/utils/index.ts Normal file
View File

@@ -0,0 +1,63 @@
import Taro from "@tarojs/taro";
// 数据库环境
// const db: any = Taro.cloud.database({
// env: "cloud1-5g5xrgza12a0dd6d",
// });
interface Typeint {
env?: any;
id?:any
tableName: any;
objData?: any;
okFun: any;
}
// 添加数据
export const addTable: any = ({ env,tableName, objData, okFun }: Typeint) => {
// 数据库环境
const db: any = Taro.cloud.database({
env: env,
});
let nowtable: any = db?.collection(tableName);
nowtable?.add({
// data 字段表示需新增的 JSON 数据
data: objData,
success: (res: any) => {
okFun(res);
},
});
};
// 获取指定集合数据
export const getTable: any = ({ env,tableName, okFun }: Typeint) => {
// 数据库环境
const db: any = Taro.cloud.database({
env: env,
});
let nowtable: any = db?.collection(tableName);
nowtable?.get({
success: (res: any) => {
okFun(res);
},
});
};
// 获取指定id数据数据
export const getTableid: any = ({ env,tableName, id, okFun }: Typeint) => {
// 数据库环境
const db: any = Taro.cloud.database({
env: env,
});
let nowtable: any = db?.collection(tableName);
nowtable?.doc(id).get({
success: (res: any) => {
okFun(res);
},
});
};