{"size": 503, "ext": "js", "max_stars_repo_path": "cloudfunctions/updateViews/index.js", "max_stars_repo_name": "ZeaKyX/HowToCookOnMiniprogram", "max_stars_repo_stars_event_min_datetime": "2022-03-05T04:29:04.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T09:31:31.000Z", "max_issues_repo_path": "cloudfunctions/updateViews/index.js", "max_issues_repo_name": "githubPgy/HowToCookOnMiniprogram", "max_issues_repo_issues_event_min_datetime": "2022-03-05T12:14:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T04:04:56.000Z", "max_forks_repo_path": "cloudfunctions/updateViews/index.js", "max_forks_repo_name": "githubPgy/HowToCookOnMiniprogram", "max_forks_repo_forks_event_min_datetime": "2022-03-11T03:14:41.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T02:35:50.000Z"}
{"max_stars_count": 320, "max_issues_count": 6, "max_forks_count": 21, "avg_line_length": 19.3461538462, "max_line_length": 59, "alphanum_fraction": 0.5447316103}
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const _ = db.command
const collection = db.collection('views')

// 云函数入口函数
exports.main = async (event) => {
  const { id, type = 'cookbook' } = event;
  const { stats } = await collection.where({ id }).update({
    data: {
      views: _.inc(1)
    }
  })
  if (stats.updated !== 1) {
    await collection.add({
      data: {
        id,
        createTime: new Date(),
        views: 1,
        type
      }
    })
  }
}
