`
sillycat
  • 浏览: 2551915 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

GraphQL 2019(3)Connect to MySQL

 
阅读更多
GraphQL 2019(3)Connect to MySQL

A nice example here
https://github.com/YuLeven/nodejs-graphql-mysql-example

Map the JSON
https://gist.github.com/microbial/b99af0a7eb11cb680c14

Lodash Documents
https://lodash.com/docs/4.17.15#keys

This project is really nice and useful
https://github.com/cheedbrands/async-mysql-wrapper
https://github.com/luohuazju/async-mysql-wrapper
https://github.com/luohuazju/xpmysql
https://github.com/baimeidaxia/xpmysql

We can add the mapping in DAO
const {Repository} = require('async-mysql-wrapper');

class EmployeeInfoDAO extends Repository {

  constructor() {
    super('employee_info', 'id', {
        'gmt_create': 'gmtCreate',
        'gmt_modified': 'gmtModified',
        'employee_id': 'employeeID',
        'rank_id': 'rankID',
        'supervisor_id': 'supervisorID',
        'tutor_id': 'tutorID'
    })
  }

  async loadAllIDAndSupervisor() {
    const query = `SELECT id, supervisor_id FROM ?? `;
    return await this.selectList(query, [this.tableName]);
  }
}
 
module.exports = new EmployeeInfoDAO();

We can use the default methods in service layer
        const employeeID = employeeItem.id;
        const employee = await EmployeeDAO.selectOneById(employeeID);
        console.log("Employee:" + JSON.stringify(employee));
        const rank = await RankDAO.selectOneById(employee.rankID);
        console.log("Rank:" + JSON.stringify(rank));
        const productInfos = await ProductInfoDAO.selectListSimple(
            {
                params: {
                    productID: item.productID,
                    rankID: employee.rankID
                }
            });
        const productInfo = _.head(productInfos);


References:
https://github.com/mysqljs/mysql#readme
https://github.com/YuLeven/nodejs-graphql-mysql-example
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics