I am using Sequalize with nodejs to insert a row in a table,now i want that last inserted id,i want some thing like "mysql_insert_id()", here is my code:
function registerAgent(agent_data,request_key,res,next)
{
  models.agent.create({creator_id: agent_data.userid },  { fields: [ 'creator_id'] }).then(function(user) {
      console.log(user);
    }); 
};
                If you are AUTO_INCREMENT with column, then you can use last_insert_id() method. This method gets the ID of the last inserted record in MySQL.
const TODAY = new Date(); const SUM = await OrdersModel. sum('price', { where: { created: Sequelize. DATE(TODAY), }, }); console. log(SUM);
The create() return the last insert element, so the last id is user.id. Is this for your problem?
function registerAgent(agent_data,request_key,res,next)
{
  models.agent.create({creator_id: agent_data.userid },  { fields: [ 'creator_id'] }).then(function(user) {
      console.log(user.id);
    }); 
};
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With