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
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error
Ad