0

The only reliable MySQL support I know of is through node-mysql and it specifically says in the documentation:

Warning: sql statements with multiple queries separated by semicolons are not supported yet.

Which kind of sucks... Because I need to insert or update a large number of rows at a time with some logic involved, and it's easily done with one large MySQL query containing IFs and ELSEs. I can't imagine how I'd simply move all the logic over to the node.js side without an enormous loss of performance and complexity in code. So I'm not ready to give up on the pure SQL solution.

Is there any way for me to execute a large SQL query from node.js relatively easily?

Hubro
  • 56,214
  • 69
  • 228
  • 381
  • For what it's worth, see this for multiple inserts in one query using MySQL: http://stackoverflow.com/questions/8899802/how-do-i-do-a-bulk-insert-in-mysql-using-node-js – The Nail Feb 04 '12 at 20:30
  • Bulk insert won't really work for me, as I need logic performed for each insert, deciding whether to insert the row or update an existing one based on date comparison and some other variables – Hubro Feb 04 '12 at 20:40

1 Answers1

1

Can you define your logic within a stored procedure and then call that as your single statement instead (passing whatever parameters you need)?

StudyOfCrying
  • 530
  • 3
  • 9
  • Sounds like a neat idea. How would I go about doing that? I have a feed where I receive everything from 5 to 40 rows at a time. Every row in my database (Could be around 1000 rows) should have their status set to "offline", then every row from the feed should be inserted into the database. They could already be there, so they should update all information in the row in that case (going by an unique column). Otherwise they should be plainly inserted. How would you recommend doing this with a stored procedure? – Hubro Feb 04 '12 at 22:44
  • Also it's important the **no** data is fetched from the table during the above procedure. That's my main issue at the moment, and the reason I want to use pure SQL (easy transactions) – Hubro Feb 04 '12 at 22:45
  • Can you provide a basic table structure and a set of test data with expected output, etc. and I'll try to help steer you down the right path? Thanks. – StudyOfCrying Feb 04 '12 at 23:36