cloudfunctions/ClearingRedundantFolders/node_modules/@cloudbase/database/src/aggregate.ts

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

import { Db } from './index'
import { EJSON } from 'bson'
import { QuerySerializer } from './serializer/query'
import { stringifyByEJSON } from './utils/utils'
import { getType } from './utils/type'

export default class Aggregation {
  _db: any
  _request: any
  _stages: any[]
  _collectionName: string
  constructor(db?, collectionName?) {
    this._stages = []

    if (db && collectionName) {
      this._db = db
      this._request = new Db.reqClass(this._db.config)
      this._collectionName = collectionName
    }
  }

  async end() {
    if (!this._collectionName || !this._db) {
      throw new Error('Aggregation pipeline cannot send request')
    }

    const result = await this._request.send('database.aggregateDocuments', {
      collectionName: this._collectionName,
      stages: this._stages
    })

    if (result && result.data && result.data.list) {
      return {
        requestId: result.requestId,
        data: result.data.list.map(EJSON.parse)
      }
    }
    return result
  }

  unwrap() {
    return this._stages
  }

  done() {
    return this._stages.map(({ stageKey, stageValue }) => {
      return {
        [stageKey]: JSON.parse(stageValue)
      }
    })
  }

  _pipe(stage, param) {
    // 区分param是否为字符串
    let transformParam = ''
    if (getType(param) === 'object') {
      transformParam = stringifyByEJSON(param)
    } else {
      transformParam = JSON.stringify(param)
    }
后面还有 75 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。