UNPKG

apass-opensdk-hugong

Version:

飞书Apass低代码平台-飞书开放平台-相关的接口整合和常用的方法整合

69 lines (62 loc) 1.97 kB
class Object_{ #hg = null constructor(hg){ this.#hg = hg } async clearData(table,id){ await application.data.object(table).select('_id').where({_id: id ? id : application.operator.gte(0)}).findStream(async records=>{ this.#hg.log4('clear data len', records.length) await application.data.object(table).batchDelete(records.map(it=>({_id: it._id}))) }) } async findList(table,field,where,callback){ const list = [] await application.data.object(table).select(field || ['_id','_name']).where(where || {_id : application.operator.gte(0)}).findStream(async records=>{ if(callback){ this.#hg.log4('find all len', list.length) await callback(records) }else{ this.#hg.log4('find all size', list.length) list.push(...records) } }) if(!callback){ this.#hg.log4('find all len', list.length) } return list } async findOne(table,field,where){ return await application.data.object(table).select(field || ['_id','_name']).where(where || {_id : application.operator.gte(0)}).findOne() } async findOneById(table,id,field){ return await application.data.object(table).select(field || ['_id','_name']).where({_id: id}).findOne() } async batchCreate(table,list){ if(list.length){ return await application.data.object(table).batchCreate(list) } return null } async create(table,data){ return await application.data.object(table).create(data) } async batchUpdate(table,list){ if(list.length){ return application.data.object(table).batchUpdate(list) } return null } async update(table,data){ return application.data.object(table).update(data) } async delete(table,_id){ return application.data.object(table).delete(_id) } async delete(table,_ids){ if(_ids.length){ return application.data.object(table).batchDelete(_ids) } return null } } module.exports = Object_