Ad

Create Stored Procedure In Mysql From 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
Ad

Answer

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);
        }
Ad
source: stackoverflow.com
Ad