node.js - would mysql js pool cause transaction deadlock -


i designing ticket system using nodejs , mysql-promise.
safety , consistency, want use transaction worry deadlock.
scenario

  1. people can buy multi tickets in 1 order
  2. i check every tickets whether rest amount of tickets enough or not.
  3. i update amount of tickets
  4. i create order

the code

        await ctx.conn.begintransaction()          // check amount of tickets         let ticketidlist = ctx.body.tickets.map(t => t._id)         let ticketlist = await models.ticket.findticketlist(ctx.conn, ticketidlist)         (let t in ticketlist) {             let ticketbook = ctx.body.tickets.filter(tb => tb._id === t._id)             if (t.perminsalecount > ticketbook.count || t.permaxsalecount < ticketbook.count) {                 ctx.stats = 400                 return ctx.body = {                     error: "failtickets"                 }             }             if (t.sold + ticketbook.count > t.total) {                 ctx.stats = 400                 return ctx.body = {                     error: "soldout"                 }             }         }          // update tickets         await promise.all(             ctx.body.tickets.map(t => models.ticket.reserveticket(ctx.conn, t._id, t.count))         )          // create order         await model.order.createorder(...)          await ctx.conn.commit() 

my big concern ctx.conn create pool

mysql.createpool({         ......     }) 

would // await promise.all(ctx.body.tickets.map(t => models.ticket.reserveticket(ctx.conn, t._id, t.count))) lines make sql in multi connections , cause deadlock ?
how use conn.begintransaction()?

thanks


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -