Felix Geisendörfer node-mysql
mendukung prosedur tersimpan, tetapi Anda harus mengakhiri prosedur tersimpan dengan SELECT
ing tanda sukses/gagal, lalu kueri seperti yang Anda lakukan SELECT
pertanyaan. Beginilah tampilan prosedur tersimpan:
DELIMITER //
DROP PROCEDURE IF EXISTS MyProcedure //
CREATE PROCEDURE MyProcedure(IN param1 VARCHAR/*, My, Parameters, ... */)
BEGIN
DECLARE EXIT HANDLER FOR NOT FOUND, SQLWARNING, SQLEXCEPTION SELECT 0 AS res;
# My Queries etc. ...
SELECT 1 AS res;
END //
DELIMITER ;
Kode Node Anda akan terlihat seperti ini:
var mysql = require('mysql');
var client = mysql.createConnection({
host : '127.0.0.1',
user : 'username',
password: 'password'
});
client.query('USE mydatabase');
var myParams = "'param1', 'param2', ... ";
client.query("CALL MyProcedure(" + myParams + ")", function(err, results, fields) {
if (err || results[0].res === 0) {
throw new Error("My Error ... ");
} else {
// My Callback Stuff ...
}
});