Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run mysql stored procedure with output return in knex.js

Tags:

mysql

api

knex.js

I have a problem with knex.js

how to call stored procedure with output in knex.js

sp string : call sp_start(1, @outmsg);

I need call that SP and select the output in return

my code:

    .get('/:headerId/recount', function(req, res, next) {

    knex.raw(
    'Call sp_start(?,?)',[req.params.headerId, @outmsg]
    )
    .then(function(result) {
       return; 
        });
  })

but it return error

like image 325
MichaelCh Avatar asked Dec 24 '22 02:12

MichaelCh


1 Answers

According to how to pass in and out parameters to a mysql stored procedure and return the stored procedure result in the nodejs code

knex.transaction(trx => {
  return knex.raw(
    'Call sp_start(?,@outmsg)',
    [req.params.headerId]
  )
  .then(res => knex.select(knex.raw('@outmsg')));
})
.then(res => console.log("Got output:", res));

should work.

like image 153
Mikael Lepistö Avatar answered Dec 28 '22 06:12

Mikael Lepistö