小程序wafer2操作数据库


小程序操作数据库


//小程序控制台phpmyadmin里给数据库cAuth添加表

//controllers/hello.js
const { mysql } = require('../qcloud')

module.exports = async ctx =>{
  console.log('exeu sql')
  var id = 2
  //add
  var book = {
    id: id,
    name: "bingyuhuozhige",
    price:88
  }
  await mysql("Book").insert(book)
  //search
  var res = await mysql("Book").where({ id }).first()
  console.log(res)
  //update
  await mysql("Book").update({ price: 66 }).where({ id })
  //search
  var res = await mysql("Book").where({ id }).first()
  console.log(res)
  //delete
  await mysql("Book").del().where({ id })
  //search
  var res = await mysql("Book").where({ id }).first()
  console.log(res)

  ctx.state.data = {
    msg: 'zheng junfei hello'
  }
}

posted @ 2019-01-02 11:58  sfornt  阅读(281)  评论(0编辑  收藏  举报