从node.js在mysql中创建存储过程 [英] create stored procedure in mysql from node.js

查看:214
本文介绍了从node.js在mysql中创建存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我必须在注册完成后立即配置数据库。
我有一个dump.sql文件,我可以使用
,但是我的存储过程未导入数据库中。
这是一个很大的过程。有没有一种方法可以从node.js创建存储过程。我尝试了,但遇到了错误。任何帮助将不胜感激。

In my project I have to a configure database as soon as registration complete. I have a dump.sql file which I am able to import and create all the required tables from .sql file using this library but my stored procedures are not getting imported in my database. It is a big procedure. Is there a way to create a stored procedure from node.js. I tried this but getting error. Any help would be greatly appreciated.

TypeError: StoredProcedures is not a constructor


推荐答案

我获得了此查询的解决方案并对其进行了回答,以便将来可以为其他人提供帮助。
我正在使用 require('require-sql');
导入sp.sql文件,然后替换 \n \r 带空格。
它可以在各自的数据库中工作并创建存储过程。

I got the solution of my this query and answering it so that could help anyone else in future. I am importing my sp.sql file using require('require-sql'); Then replacing \n\r with space. It works and create stored procedure in respective database.

 var query = require(path.join(_dirname, '/app/helper/sql/sp_distribute_all_data.sql'));
        try {
            conn(dbname).query(query.replace(/\r?\n|\r/g, " "), function (err, result) {
                if (err) {
                    console.log("ERROR:::", err);
                    resolve({
                        status: false,
                        feedback: err
                    });
                } else {
                    console.log("RESULT:::", result);
                    resolve({
                        status: true,
                        companyId: companyId,
                        feedback: 'Company configured successfully !!'
                    });
                }

            });
        } catch (error) {
            var stack = error.stack;

            console.log(stack);
        }

这篇关于从node.js在mysql中创建存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆