knex.js查询数据库

1.get请求

const { mysql } = require('../qcloud')
// 按照openid查找收藏列表
async function collectFindByOpenId(ctx, next) {
    await mysql('songlist').
    join('collect', 'songlist.id', '=', 'collect.songid').
    select('*').
    where({
        openid: ctx.query.openid
    }).
    then(res => {
        ctx.state.code = 0
        ctx.state.data = res
    }).catch(err => {
        ctx.state.code = -1
        throw new Error(err)
    })
}
module.exports = {
    collectFindByOpenId
}

2.post请求

3.delete请求

4.put请求

Last updated