koa 2で使われているmysqlのまとめ
1546 ワード
直接コード:
router.get('/', async (ctx, next) => {
await ctx.render('index', {
title: 'Hello Koa 2!'
})
})
router.get('/string', async (ctx, next) => {
let ev = 1;
let age = 60
/** */
sql.query(`select id from user where id=${ev}&&age=${age}`, (err, result) => {
console.log(result, err, '-----------addd');
})
ctx.body = 'koa2 s tring'
})
router.get('/json', async (ctx, next) => {
let obj = {
id: 2,
name: ' ',
age: 28
}
/** */
sql.query(`UPDATE user SET name='${obj.name}' where id=${obj.id}`, (error, result) => {
console.log(error, 'error--------------');
console.log(result, 'result');
})
ctx.body = {
title: 'koa2 json'
}
})
router.get('/test', async (ctx, next) => {
let obj = {
id: 3,
name: ' ',
age: 88
}
/** */
sql.query(`INSERT INTO user (id, name, age) VALUES (${obj.id},'${obj.name}', ${obj.age})`, (error,result) => {
console.log(error, ' ');
console.log(result, ' ');
})
ctx.body = {
title: ' '
}
})
router.get('/ot', async (ctx, next) => {
/** */
let id = 3;
sql.query(`DELETE FROM user WHERE id='${id}'`, (error,result) => {
console.log(error, ' ');
console.log(result, ' ');
})
ctx.body = {
title: ' '
}
})
module.exports = router