简体   繁体   English

MySQL与NodeJS后端和ReactJS前端的集成

[英]Integration of MySQL with NodeJS Backend and ReactJS FrontEnd

I want to develop an ERP application with ReactJs in FrontEnd, NodeJS in BackEnd and MySQL for the database. 我想开发与前端ReactJs,的NodeJS后端和MySQL数据库的ERP应用。

My ERP is also the management of customers, suppliers, purchase orders, delivery notes and products. 我的ERP还管理客户,供应商,采购订单,交货单和产品。

I want to know about the integration of MySQL with NodeJS does it require ORM models like Sequelize? 我想了解MySQL与NodeJS的集成,是否需要Sequelize之类的ORM模型?

Thanks in advance. 提前致谢。

There is no absolute need for an ORM. 绝对不需要ORM。 You can install the mysql driver for node.js through npm and include it in your project. 您可以通过npm安装用于node.js的mysql驱动程序,并将其包含在您的项目中。 The documentation can be found here: https://www.npmjs.com/package/mysql 该文档可以在这里找到: https : //www.npmjs.com/package/mysql

You could implement it like this: 您可以这样实现:

var sql = require('mssql');

var config = {
    user: "databaseAccountUsername",
    password: "databaseAccountPassword",
    server: "databaseServerAddress",
    database: "databaseName",
    options: {
        encrypt: false
    }
}

const pool = new sql.ConnectionPool(config);
    pool.connect(err => {
    if(err) {
        console.log(err)
    }
});

function getCustomers() {
    var request = new sql.Request(pool);
    request.query("SELECT customer_id, first_name FROM customers")
    .then((result) => {
        res.end(JSON.stringify(result.recordsets[0]));
    })
    sql.close();
}

I suggest making your queries in your routes and handling them with express or any other request/response library 我建议您在路线中进行查询,并使用快速或任何其他请求/响应库进行处理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM