美文网首页
node-mysql-pro

node-mysql-pro

作者: 秋天de童话 | 来源:发表于2018-09-03 23:39 被阅读11次

    https://npm.taobao.org/package/mysql-pro
    server-mysqlpro.js

    const koa = require('koa');
    const router = require('koa-router');
    const DB = require('mysql-pro');
    
    let db = new DB({
        mysql: {
            host:'127.0.0.1',
            port:'3306',
            database: '20180211',
            user:'root',
            password:'admin'
        }
    })
    
    let server = new koa();
    server.listen(8080);
    
    let r1 = router();
    server.use(r1.routes());
    
    r1.get('/user',async ctx=>{
    
        try{
            await db.startTransaction();
            let data = await db.executeTransaction(`select * from user_table`,[]);
            await db.stopTransaction();
            console.log(data);
            ctx.response.body = data;
        }catch(e){
            ctx.response.body = '数据库获取异常';
        }
    })
    
    image.png

    相关文章

      网友评论

          本文标题:node-mysql-pro

          本文链接:https://www.haomeiwen.com/subject/pugiwftx.html