0

https://github.com/felixge/node-mysql#custom-format

Does changing this method effect all connections in a pool?

Does it effect only the current connection? If so, when I release it back into the pool, will it continue to have the modified method when it is used by another routine? If so, how do I reset it back to it's default?

I want to use queryFormat to allow for hash parameters like the example shows. But, the issue is that I already wrote so much code that uses arrays. I could modify the example to allow either arrays or hashes. All-in-all, I'd still like to know more about how modifying this method effects the connection and pool.

Sam
  • 6,414
  • 11
  • 46
  • 61

1 Answers1

0

Perusing the code seems to indicate that config.queryFormat is unique to each instantiated Connection, so you could just create two different connections with different queryFormats.

Zach Kelling
  • 52,505
  • 13
  • 109
  • 108
  • If the connection is from a pool, then it will be re-used by another place in my code eventually. Wouldn't I need to reset it before I release the connection back into the pool? – Sam Mar 27 '14 at 06:40
  • Not necessarily, no. You will get a new `Connection` object each time you call `pool.getConnection`. – Zach Kelling Mar 28 '14 at 06:10
  • I thought pooled connections stay alive in the pool? Otherwise, what's the point of having a pool? – Sam Mar 31 '14 at 00:14
  • The pool lets you reuse the connections under the cover, yes. You are not necessarily creating a new connection each time you call `pool.getConnection`. You are however getting a new `Connection` instance. – Zach Kelling Apr 02 '14 at 15:29
  • Ah, I see. How would I make the queryFormat the same for all connections in the pool? I figured I could support both Arrays and Objects as the parameters to be formatted into the query. – Sam Apr 04 '14 at 05:52