Re: how to keep my code to connect to web server in order to do transaction

46 views
Skip to first unread message

Ryan Lee

unread,
Jan 23, 2015, 2:53:52 AM1/23/15
to node-...@googlegroups.com
It's in the docs:


If you're new to node.js, make sure you learn how to do flow control. It will make your code cleaner and save you a lot of head ache down the road.

Ryan

On Fri, Jan 23, 2015 at 2:27 AM, Hualu Qi <hualu.w...@gmail.com> wrote:
Hi People,

              my business logical is try to balance user's money in diff tables, so i need a transaction to reach the target, but my boss doesn't want me to use stored procedure. so i need open a transaction.


              does anyone can lead me to sunshine?


             if possible, could you please share me what is the module of nodes to MySQL transaction? and how does node.js make it works. i am a new guys in there, but i am a quick leaner!

Thanks. William 
          

--
You received this message because you are subscribed to the Google Groups "node-mysql" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-mysql+...@googlegroups.com.
To post to this group, send email to node-...@googlegroups.com.
Visit this group at http://groups.google.com/group/node-mysql.
For more options, visit https://groups.google.com/d/optout.

klrumpf

unread,
Jan 23, 2015, 3:55:04 AM1/23/15
to node-...@googlegroups.com
I use koa now with yield etc., not express but in callback style I'd use the connection pool and
then a pattern (or async module) to ensure sequential execution, for example (in pseudo code)

func1()...
   "begin work"..
   call func2()...

func2()
   "do your sql operation #1..."
   if error
       "rollback work"
       message "transaction failed"
   else
      call func3()

func3()
   "do your next sql operartion .."
   if error
     "rollback work"
     message "transaction failed"
   else
     call func4()
 
func4()
   "commit work"
   message "transaction terminated"

call func1()


if you have problems try set connectionLimit to 1 in the mysql config just for the transaction, I think it has to run all under the same one connection. Untested, hope this helps.
On 23/01/15 03:27, Hualu Qi wrote:
Reply all
Reply to author
Forward
0 new messages