{"_id":"mysql-queues","_rev":"47-11d62f324a792b4edfd479faf56f5681","name":"mysql-queues","description":"Wraps 'mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.","dist-tags":{"latest":"1.0.0"},"versions":{"0.2.0":{"author":{"name":"Blake Miner","email":"miner.blake@gmail.com","url":"http://www.blakeminer.com"},"name":"mysql-queues","description":"Wraps 'mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.","version":"0.2.0","homepage":"https://github.com/bminer/node-mysql-queues","repository":{"type":"git","url":"git://github.com/bminer/node-mysql-queues.git"},"main":"index.js","engines":{"node":">=0.4.0"},"dependencies":{"mysql":">=0.9.5"},"devDependencies":{},"keywords":["mysql","transaction","multiple statements","queue","query","database"],"_npmUser":{"name":"bminer","email":"miner.blake@gmail.com"},"_id":"mysql-queues@0.2.0","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.6.2","_defaultsLoaded":true,"dist":{"shasum":"d1e59b78188990a237b6df3ed3ea8256df2cb4dd","tarball":"https://registry.npmjs.org/mysql-queues/-/mysql-queues-0.2.0.tgz","integrity":"sha512-a1Xr83/ufzb1k1TzcCoEEdBvQjWnuC0a3uPhkRUIyys/yH/3fJeA7MDeUz531DtSGEnWa+mGAa0aGBYgJ14nfQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCr2HNCqFEA86g/vNqpS3ndjel+F1GEuunXKlEbTV3DygIhAKvplbRNZA+9uYXfU/AyeIiqKqnuULDg+V39dURpL6Rw"}]},"maintainers":[{"name":"bminer","email":"miner.blake@gmail.com"}],"directories":{},"deprecated":"This library is no longer needed because node-mysql supports transactions"},"0.2.1":{"author":{"name":"Blake Miner","email":"miner.blake@gmail.com","url":"http://www.blakeminer.com"},"name":"mysql-queues","description":"Wraps 'mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.","version":"0.2.1","homepage":"https://github.com/bminer/node-mysql-queues","repository":{"type":"git","url":"git://github.com/bminer/node-mysql-queues.git"},"main":"index.js","engines":{"node":">=0.4.0"},"dependencies":{"mysql":">=0.9.5"},"devDependencies":{},"keywords":["mysql","transaction","multiple statements","queue","query","database"],"_npmUser":{"name":"bminer","email":"miner.blake@gmail.com"},"_id":"mysql-queues@0.2.1","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.6.2","_defaultsLoaded":true,"dist":{"shasum":"30be7bde4b73e4acf8b28adfb2dc433ea809a221","tarball":"https://registry.npmjs.org/mysql-queues/-/mysql-queues-0.2.1.tgz","integrity":"sha512-SIeTK87wba3K7vF5wExcd60Gdv93NewYHWKcVZZewJKK1PG2k/jytKCQIRmc3t1jlqHHj1kDR31rWVhHMqycOA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC4eJgzZzMwFNy3YuAk8V2EPrZyw/8SrSQv/B0UQy39VgIgfJQMMDxZ7v4+46QaFUXOhie6v6qaoSBkoFmbttznbNE="}]},"maintainers":[{"name":"bminer","email":"miner.blake@gmail.com"}],"directories":{},"deprecated":"This library is no longer needed because node-mysql supports transactions"},"0.2.2":{"author":{"name":"Blake Miner","email":"miner.blake@gmail.com","url":"http://www.blakeminer.com"},"name":"mysql-queues","description":"Wraps 'mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.","version":"0.2.2","homepage":"https://github.com/bminer/node-mysql-queues","repository":{"type":"git","url":"git://github.com/bminer/node-mysql-queues.git"},"main":"index.js","engines":{"node":">=0.4.0"},"dependencies":{"mysql":">=0.9.5"},"devDependencies":{},"keywords":["mysql","transaction","multiple statements","queue","query","database"],"_npmUser":{"name":"bminer","email":"miner.blake@gmail.com"},"_id":"mysql-queues@0.2.2","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.6.2","_defaultsLoaded":true,"dist":{"shasum":"361a15c511885ace4b0ef08f7c2fce457d8065fe","tarball":"https://registry.npmjs.org/mysql-queues/-/mysql-queues-0.2.2.tgz","integrity":"sha512-sFLilGaLlW18hhcy9goFjenFTN7q4HNGpr1sC/lFFXXRBIUxy+S0XCNydXdpe7X04tap/SXt9VVL4iil3xNRAA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDKMaXIdMT9RuF/GN3d2t0Jnuf8FKRV5AdqgIkHwKBO9wIhANbYMoJW2lycUX8B/+I76lx9nj0TpYaqfemNTgjpKbux"}]},"maintainers":[{"name":"bminer","email":"miner.blake@gmail.com"}],"directories":{},"deprecated":"This library is no longer needed because node-mysql supports transactions"},"0.3.0":{"author":{"name":"Blake Miner","email":"miner.blake@gmail.com","url":"http://www.blakeminer.com"},"name":"mysql-queues","description":"Wraps 'mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.","version":"0.3.0","homepage":"https://github.com/bminer/node-mysql-queues","repository":{"type":"git","url":"git://github.com/bminer/node-mysql-queues.git"},"main":"index.js","engines":{"node":">=0.4.0"},"dependencies":{"mysql":">=0.9.5"},"devDependencies":{},"keywords":["mysql","transaction","multiple statements","queue","query","database"],"_npmUser":{"name":"bminer","email":"miner.blake@gmail.com"},"_id":"mysql-queues@0.3.0","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.6.2","_defaultsLoaded":true,"dist":{"shasum":"1d1126c71e2e8a534d83840033690801b01d32b6","tarball":"https://registry.npmjs.org/mysql-queues/-/mysql-queues-0.3.0.tgz","integrity":"sha512-JhZtz2ZdFEhmBznqJZA0GKKMWRfqJPgFpbMe92g1eDBrGBWAj8uBYteCLG2Zkz8oZj0FATJvXpY9g6J2rV7ifg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHz9LO0ymsxOjhTUAd/ZXYpweVrMPjStCNFPD8G1bp5xAiEAyN/a8oZZtL4ciQhqzClaJG0sYQz4C9ARFAwY71Wg99A="}]},"maintainers":[{"name":"bminer","email":"miner.blake@gmail.com"}],"directories":{},"deprecated":"This library is no longer needed because node-mysql supports transactions"},"0.2.3":{"author":{"name":"Blake Miner","email":"miner.blake@gmail.com","url":"http://www.blakeminer.com"},"name":"mysql-queues","description":"Wraps 'mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.","version":"0.2.3","homepage":"https://github.com/bminer/node-mysql-queues","repository":{"type":"git","url":"git://github.com/bminer/node-mysql-queues.git"},"main":"index.js","engines":{"node":">=0.4.0"},"dependencies":{"mysql":">=0.9.5"},"devDependencies":{},"keywords":["mysql","transaction","multiple statements","queue","query","database"],"_npmUser":{"name":"bminer","email":"miner.blake@gmail.com"},"_id":"mysql-queues@0.2.3","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.6.2","_defaultsLoaded":true,"dist":{"shasum":"5de69a4de4184ba5252c56b9bb2bd348610fa8e6","tarball":"https://registry.npmjs.org/mysql-queues/-/mysql-queues-0.2.3.tgz","integrity":"sha512-YYkzRrB4d2OuGadMRG8YNDieX74Bd05N9yMPusRhgaU1E7vmtlIqz6yueiHv78dH3GhyhnlGxCSMPAWNVRIlQQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHmsAEDZR+Yvvs8GSwLAA/eQN1wsTJlJ8Blaj9SQjPE8AiEA6mF+riAh9afjm8uZ2zPGBope9jOEc+BDllUkoPf1u6o="}]},"maintainers":[{"name":"bminer","email":"miner.blake@gmail.com"}],"directories":{},"deprecated":"This library is no longer needed because node-mysql supports transactions"},"0.3.1":{"author":{"name":"Blake Miner","email":"miner.blake@gmail.com","url":"http://www.blakeminer.com"},"name":"mysql-queues","description":"Wraps 'mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.","version":"0.3.1","homepage":"https://github.com/bminer/node-mysql-queues","repository":{"type":"git","url":"git://github.com/bminer/node-mysql-queues.git"},"main":"index.js","engines":{"node":">=0.4.0"},"dependencies":{"mysql":">=0.9.5"},"bugs":{"url":"https://github.com/bminer/node-mysql-queues/issues"},"devDependencies":{},"keywords":["mysql","transaction","multiple statements","queue","query","database"],"_npmUser":{"name":"bminer","email":"miner.blake@gmail.com"},"_id":"mysql-queues@0.3.1","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.6.2","_defaultsLoaded":true,"dist":{"shasum":"5a4649c6a982dac9234bdb4f61f00abdd681e55f","tarball":"https://registry.npmjs.org/mysql-queues/-/mysql-queues-0.3.1.tgz","integrity":"sha512-In2lVi06upp23hO+kp9aj1nmkvCyylJ+T/ErqUoJTyJcQ5c/QrjaN4pMst3yaNtVbUaZaSkyKh93I28mmKeM0w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCORXjcbSW3kxE+R1I4Podfj3Yua5dPT5kiykdH0N+q6QIhANCXSAKuncsz9od8etlTYd2qDUsfEmlen1neKldxaYD/"}]},"maintainers":[{"name":"bminer","email":"miner.blake@gmail.com"}],"deprecated":"This library is no longer needed because node-mysql supports transactions"},"0.3.2":{"author":{"name":"Blake Miner","email":"miner.blake@gmail.com","url":"http://www.blakeminer.com"},"name":"mysql-queues","description":"Wraps 'mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.","version":"0.3.2","homepage":"https://github.com/bminer/node-mysql-queues","repository":{"type":"git","url":"git://github.com/bminer/node-mysql-queues.git"},"main":"index.js","engines":{"node":">=0.4.0"},"dependencies":{"mysql":">=0.9.5"},"bugs":{"url":"https://github.com/bminer/node-mysql-queues/issues"},"devDependencies":{},"keywords":["mysql","transaction","multiple statements","queue","query","database"],"_npmUser":{"name":"bminer","email":"miner.blake@gmail.com"},"_id":"mysql-queues@0.3.2","_engineSupported":true,"_npmVersion":"1.0.106","_nodeVersion":"v0.6.2","_defaultsLoaded":true,"dist":{"shasum":"e1686a2f12301460990c40e5f32ea19acd7bc684","tarball":"https://registry.npmjs.org/mysql-queues/-/mysql-queues-0.3.2.tgz","integrity":"sha512-77UtE8mczf2Cr3Wg0p73LNpzSS96vUmBwlo6nTT6AOJsBUdgrlEFhL94gsjRFXhgIqpehiz/mmhVNOfEKEoNJQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCIb3Yg30P/l+x100lBQ2VPrXcgu6aAnh+R37m8EnV2dgIhAM72Qf3m1dOWN8ulE/KxrWqaEfty++O6JK+7ZPmK3pN9"}]},"maintainers":[{"name":"bminer","email":"miner.blake@gmail.com"}],"deprecated":"This library is no longer needed because node-mysql supports transactions"},"0.3.3":{"author":{"name":"Blake Miner","email":"miner.blake@gmail.com","url":"http://www.blakeminer.com"},"name":"mysql-queues","description":"Wraps 'mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.","version":"0.3.3","homepage":"https://github.com/bminer/node-mysql-queues","repository":{"type":"git","url":"git://github.com/bminer/node-mysql-queues.git"},"main":"index.js","engines":{"node":">=0.4.0"},"dependencies":{"mysql":">=0.9.5"},"bugs":{"url":"https://github.com/bminer/node-mysql-queues/issues"},"devDependencies":{},"keywords":["mysql","transaction","multiple statements","queue","query","database"],"_npmUser":{"name":"bminer","email":"miner.blake@gmail.com"},"_id":"mysql-queues@0.3.3","_engineSupported":true,"_npmVersion":"1.1.0-beta-10","_nodeVersion":"v0.6.2","_defaultsLoaded":true,"dist":{"shasum":"af801e571c9b2f56f8500eb0d57e746735dbb4e4","tarball":"https://registry.npmjs.org/mysql-queues/-/mysql-queues-0.3.3.tgz","integrity":"sha512-7nFXEYznLl9z0uCUJKkcNNxXwkgonWbt4PkEdcaz0wSCuDcQKuzmJdLUcvzAf5F6T8y9DXvLzJLZIancem0bIA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCIlCRGFXUZPHfmUioNiRWZRJxVR1juBnDSRw+05eRdHAIgTy8XlbjZtuYqtdxPUsQJxC5+5uFERD+d4HFC32mFpMc="}]},"maintainers":[{"name":"bminer","email":"miner.blake@gmail.com"}],"deprecated":"This library is no longer needed because node-mysql supports transactions"},"0.3.4":{"author":{"name":"Blake Miner","email":"miner.blake@gmail.com","url":"http://www.blakeminer.com"},"name":"mysql-queues","description":"Wraps 'mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.","version":"0.3.4","homepage":"https://github.com/bminer/node-mysql-queues","repository":{"type":"git","url":"git://github.com/bminer/node-mysql-queues.git"},"contributors":[{"name":"Tom Atkinson","email":"atkinson.tommy@neosoft.ba"}],"main":"index.js","engines":{"node":">=0.4.0"},"dependencies":{"mysql":">=0.9.5"},"bugs":{"url":"https://github.com/bminer/node-mysql-queues/issues"},"devDependencies":{},"keywords":["mysql","transaction","multiple statements","queue","query","database"],"_npmUser":{"name":"bminer","email":"miner.blake@gmail.com"},"_id":"mysql-queues@0.3.4","optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.4","_nodeVersion":"v0.6.12","_defaultsLoaded":true,"dist":{"shasum":"b07691cd94d709627e94a95d9b2c85a3e68def64","tarball":"https://registry.npmjs.org/mysql-queues/-/mysql-queues-0.3.4.tgz","integrity":"sha512-BBBYGVj/VsuIp5QsFW+2qbsaMjzswZkV4TVbJZJFY7UQIKyrMAvMpHAnygrCjbs8cuHGSEDy6VlZLw4DyjUp3g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGM9SAujm3+llH8deAXm6c9m4skMJiT63GZe8eU7Zjc6AiEA9AYVFcPtjJ707dpusEJ4i3L159N4ZKYEMNDS7SK0wvo="}]},"maintainers":[{"name":"bminer","email":"miner.blake@gmail.com"}],"deprecated":"This library is no longer needed because node-mysql supports transactions"},"0.3.5":{"author":{"name":"Blake Miner","email":"miner.blake@gmail.com","url":"http://www.blakeminer.com"},"name":"mysql-queues","description":"Wraps 'mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.","version":"0.3.5","homepage":"https://github.com/bminer/node-mysql-queues","repository":{"type":"git","url":"git://github.com/bminer/node-mysql-queues.git"},"contributors":[{"name":"Tom Atkinson","email":"atkinson.tommy@neosoft.ba"},{"name":"Kris Reeves","email":"krisreeves@searchfanatics.com"}],"main":"index.js","engines":{"node":">=0.4.0"},"dependencies":{"mysql":">=0.9.5"},"bugs":{"url":"https://github.com/bminer/node-mysql-queues/issues"},"devDependencies":{},"keywords":["mysql","transaction","multiple statements","queue","query","database"],"_npmUser":{"name":"bminer","email":"miner.blake@gmail.com"},"_id":"mysql-queues@0.3.5","optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.16","_nodeVersion":"v0.6.12","_defaultsLoaded":true,"dist":{"shasum":"5586839114f9963d64b0477b6a112bae5412015d","tarball":"https://registry.npmjs.org/mysql-queues/-/mysql-queues-0.3.5.tgz","integrity":"sha512-nYWh471EiRhor6T5fWKkGYbn62n2UdwtE/VsexrHcqFUnLYH6gYLZwXLVpDEnS4hvweQzAfLgILcTvHbIA4V3A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICdWlLxJSSErWQAUDsTBr5fRCArbaP/Y3sX0hS9D4Rp+AiBcF97S1n8xbt/vlteVtkw9OGt6KCLpDSBITwmsSST4/g=="}]},"maintainers":[{"name":"bminer","email":"miner.blake@gmail.com"}],"deprecated":"This library is no longer needed because node-mysql supports transactions"},"1.0.0":{"author":{"name":"Blake Miner","email":"miner.blake@gmail.com","url":"http://www.blakeminer.com"},"name":"mysql-queues","description":"Wraps 'mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.","version":"1.0.0","homepage":"https://github.com/bminer/node-mysql-queues","repository":{"type":"git","url":"git://github.com/bminer/node-mysql-queues.git"},"contributors":[{"name":"Tom Atkinson","email":"atkinson.tommy@neosoft.ba"},{"name":"Kris Reeves","email":"krisreeves@searchfanatics.com"}],"main":"index.js","engines":{"node":">=0.4.0"},"optionalDependencies":{"mysql":">=0.9.5"},"bugs":{"url":"https://github.com/bminer/node-mysql-queues/issues"},"devDependencies":{},"keywords":["mysql","transaction","multiple statements","queue","query","database"],"readme":"# node-mysql-queues\n\nAdd your own node-mysql query queues to support transactions and multiple statements.\n\nFor use with Node.js and node-mysql: https://github.com/felixge/node-mysql\n\n## Background\n\nnode-mysql does not provide an API for MySQL transactions (yet).\n\nThere are a few problems with this:\n\n- If you use the same database connection for 2 or more requests, then you can run\n\tinto an issue where queries that should not intermix, end up intermixing.\n\tThis can mess up MySQL transactions.\n- There is no nice API to start, commit, or rollback transactions.\n\nFortunately, there are a few solutions:\n\n- The easy solution: create a new connection to the database for each request, or\n\tto be extra safe, create a new connection for each transaction.  This is\n\tprobably what PHP does.  Unfortunately, a new connection for each request\n\tcan get expensive and slightly harm performance.\n- The other solution: node-mysql-queues.  The idea behind node-mysql-queues is\n\tthat we create separate query queues to ensure that queries in a particular\n\tqueue do not overlap with queries in another queue; that is, they get executed\n\tin order, as expected. Plus, you have a nice, simple API for MySQL\n\ttransactions. The disadvantage is that other requests with DB queries need\n\tto block while a transaction is executed, but I'm not sure about the effect\n\ton performance here.\n\nAll that being said, this project is still being actively maintained.  It has\nalso been tested with node-mysql 2.0.\n\n## Install\n\n`npm install mysql-queues`\n\n## Usage\n\n```javascript\nvar mysql = require('mysql');\nvar client = mysql.createClient({\n\tuser: 'root',\n\tpassword: 'root'\n});\n//Enable mysql-queues\nvar queues = require('mysql-queues');\nconst DEBUG = true;\nqueues(client, DEBUG);\n//Start running queries as normal...\nclient.query(...);\n\n//Now you want a separate queue?\nvar q = client.createQueue();\nq.query(...); \nq.query(...);\nq.execute();\n\nclient.query(...); //Will not execute until all queued queries (and their callbacks) completed.\n\n//Now you want a transaction?\nvar trans = client.startTransaction();\ntrans.query(\"INSERT...\", [x, y, z], function(err, info) {\n\tif(err)\n\t\ttrans.rollback();\n\telse\n\t\ttrans.query(\"UPDATE...\", [a, b, c, info.insertId], function(err) {\n\t\t\tif(err)\n\t\t\t\ttrans.rollback();\n\t\t\telse\n\t\t\t\ttrans.commit();\n\t\t});\n});\ntrans.execute();\n//No other queries will get executed until the transaction completes\nclient.query(\"SELECT ...\") //This won't execute until the transaction is COMPLETELY done (including callbacks)\n\n//Or... as of version 0.3.0, you can do this...\nvar trans = client.startTransaction();\nfunction error(err) {\n\tif(err && trans.rollback) {trans.rollback(); throw err;}\n}\ntrans.query(\"DELETE...\", [x], error);\nfor(var i = 0; i < n; i++)\n\ttrans.query(\"INSERT...\", [ y[i] ], error);\ntrans.commit(); //Implictly calls resume(), which calls execute()\n/* In the case written above, COMMIT is placed at the end of the Queue, yet the\nentire transaction can be rolled back if an error occurs. Nesting these queries\nwas not required. */\n\n```\nEven multiple Queues work! They get executed in the order that `execute()` is called.\n\n## How it works\n\n* If I'm a client.query() call or a Queue.execute() call...\n\t* If a Queue is currently executing\n\t\t* Place me on the main queue to be executed\n\t* Otherwise, Execute me now\n\t\t* Run all queries in the Queue in order\n\t\t* Wait for all query callbacks to complete. When they all complete, continue.\n\t\t* If the callback added more queries to this Queue, then jump to \"Execute me now\"\n\t\t* Otherwise\n\t\t\t* If this Queue is a transaction that has not been committed, then\n\t\t\tcommit it now and issue a warning message.\n\t\t\t* Finally, Return control to the main queue by executing all queued queries\n\n## API\n\n### client.query(sql, [params, cb])\n\nUse normally. Same as node-mysql, except that if a Queue is still pending\ncompletion, this query may be queued for later execution.\n\n### client.createQueue()\n\nCreates a new query Queue.\n\n### client.startTransaction()\n\nCreates a new query Queue with \"START TRANSACTION\" as the first queued query.\nThe Queue object will also have `commit()` and `rollback()` methods.\n\n### Queue.query(sql, [params, cb])\n\nSame as node-mysql. This query will be queued for execution until `execute()`\nis called on the `Queue`.\n\n### Queue.execute()\n\nExecutes all queries that were queued using `Queue.query`. Until all query\n*callbacks* complete, it is guaranteed that all queries in this Queue\nwill be executed in order, with no other queries intermixed.  That is, during\nexecution of this query Queue, all queries executed using `client.query` will\nbe queued until this Queue is empty and all callbacks of this Queue have\nfinished executing. That means that a query added to a Queue can also queue\na query using `Queue.query`, and it will be executed before any `client.query`\ncall. Thus, nested query queueing is supported in query callbacks, allowing\nsupport for transactions and more.\nSee the source code for further documentation.\n\nCalling `execute()` on an already executing Queue has no effect.\nCalling `execute()` on a paused Queue has no effect. (see `pause()` below)\n\nNote: Once `execute()` is called and all queries have completed, the Queue\nwill be empty again, returning control to either: (a) another Queue that has been\nqueued for execution; or (b) the main node-mysql queue (a.k.a. queries executed\nwith `client.query`). Once a Queue is empty and has finished executing, you may\ncontinue to use `Queue.query` and `Queue.execute` to queue and execute more\nqueries; however, as noted below, you should *never* reuse a Queue created by\n`client.startTransaction`\n\n### Queue.commit([cb])\n\nAvailable only if this Queue was created with `client.startTransaction`.\nCalls `cb(err, info)` when the COMMIT has completed.\n\nAs of version 0.3.0, the behavior of `commit()` is:\n\n * If the queue is empty when `commit()` is called, then 'COMMIT' will be\n queued to be executed immediately. If this behavior is desired, and you\n are not sure if the queue will be empty, simply call `resume()`\n before calling `commit()`.\n * If the queue is not empty when `commit()` is called, then 'COMMIT' will\n be queued for execution when the queue is empty and all query callbacks\n have completed.\n\nCalling `commit()` also implicitly calls `resume()` on the Queue.\n\nYou may only call `commit()` once. Once you call `commit()` on this Queue,\nyou should discard it. To avoid calling `commit()` twice, you can check\nto see if it exists; once you call `commit()`, in most circumstances, the\nfunction is deleted from the Queue object after it is called.\n\nAs of version 0.3.0, it is sometimes\npossible to call `rollback()` even after `commit()` has been called.\nIf 'COMMIT' is queued for execution (i.e. if the queue is *not* empty when\n`commit()` is called), then you may call `rollback()` on this Queue,\nas long as `rollback()` occurs before the 'COMMIT' is executed (i.e. when the\nQueue is empty and all query callbacks have completed).\nYou might use the functionality in a scenario where you only want your query\ncallbacks to call `rollback()` if an error occurred (i.e. a foreign key\nconstraint was violated). If no error occurs, you want to call `commit()`.\nRather than nesting all of these queries to determine whether or not to\ncall `commit()` or `rollback()`, you can simply queue up all of your queries,\ncall `commit()` to queue up a 'COMMIT', and call `rollback()` in your\nquery callbacks if an error occurs.\n\n### Important Note!\n\nIf you do not call `commit()` or `rollback()` and the Queue has completed\nexecution, `commit()` will be called automatically to end the transaction;\nhowever, one should **NOT** rely on this behavior. In fact, mysql-queues\nwill print nasty warning messages if you do not explicitly `commit()` or\n`rollback()` a transaction.\n\n### Queue.rollback([cb])\n\nAvailable only if this Queue was created with `client.startTransaction`.\nThis executes 'ROLLBACK' immediately, purges the remaining queries in the\nqueue, and immediately returns control to the main queue. Finally, the\ncallback `cb(err, info)` is called when the ROLLBACK has completed.\n\nYou may only call `rollback()` once. To avoid calling it twice, you can\ncheck to see if it exists; once you call `rollback()`, the function is\ndeleted from the Queue object. Also, once you call `rollback()`, you cannot\ncall `commit()`.\n\nNote: Before 0.2.3, `rollback()` would add the 'ROLLBACK' query to the Queue\nand the Queue would continue executing. This was changed in 0.2.3 because it\nis more natural for a ROLLBACK operation to abort the remaining Queue, since\nit will be rolled back anyway. As mentioned above, this also allows you to\nqueue the COMMIT query at the bottom of the queue, and if an error occurs\nbefore the COMMIT, you can safely `rollback()` the entire transaction.\n\n### Queue.pause([maxWaitDuration])\n\nPauses the Queue, preventing it from returning control to the next Queue or\nto the main node-mysql Queue. You can call `resume()` to resume the Queue,\nor if the Queue is a transaction, `commit()` or `rollback()` will\nautomatically resume the Queue.\n\nBy default, the Queue will remain paused until you call `resume()` or end\nthe transaction; however, you may set an optional maximum wait duration,\nwhich will prevent the Queue from pausing for too long.\n\n*CAUTION:* A paused Queue will block all queries for this connection.\n*Use with care.*\n\nPausing a Queue is useful to make additional asynchronous calls within a\nquery callback. An example of this is shown below.\n\n### Queue.resume()\n\nResumes Queue execution. This function basically unpauses the Queue and\ncalls `execute()`.\n\n### require('mysql-queues')(client, debug)\n\nAttaches mysql-queues to the mysql client. When `debug` mode is enabled,\ndebugging messages are printed to standard error when certain exceptions occur.\nWhen you queue a query, the call stack becomes somewhat useless, and it can\nbecome difficult to determine which query is causing a problem. The debug\nfeature allows you to more easily determine which query that caused a problem.\n\n## Don't do this...\n\n```javascript\n//You may be tempted to do this...\nvar fs = require('fs');\nvar trans = db.startTransaction();\ntrans.query(\"INSERT ...\", [...], function(err, info) {\n\tfs.readFile(\"foobar.txt\", function(err, data) {\n\t\t//By now, it's too late to use `trans`\n\t\tif(data == \"something\")\n\t\t\ttrans.commit();\n\t\telse\n\t\t\ttrans.rollback();\n\t});\n\t//The query callback is now done!! This is your last chance\n\t//to call `commit` or `rollback`\n}).execute();\n```\n\nIn the case above, an asynchronous call was placed in the query callback.\nThis won't work as expected. The query callback completes and automatically\nexecutes `commit()` before the asychronous filesystem call completes. In this\nexample, you will get a warning message, your transaction will be committed\nno matter what, and your program may throw an exception after the I/O\noperation completes (because neither `commit()` nor `rollback()` can be\ncalled more than once).\n\nTo be clear, the scope of this problem is *not* limited by asynchronous\nfile I/O operations; any asychronous call can cause this problem - even a\nquery to another database will cause this problem (i.e. if you execute a\nseries of MySQL queries and then update Redis, for example)\n\n### Fortunately, there are a few solutions...\n\nPossible solutions include: (in order of personal preference)\n\n * Performing your asynchronous operation BEFORE you execute any queued\n queries (i.e. we could have read \"foobar.txt\" first, then executed the query).\n I understand... most of the time, this is not possible.\n * Call `Queue.pause()` right before the asynchrous operation. This is the\n easy way out, but it comes at a small cost. If you pause a Queue, no query\n can be executed during the asynchronous operation. So, for scalability\n reasons, be sure that your asynchronous operation runs quickly (i.e. a Redis\n command or something). Don't do any video encoding on a 1 GB file.\n * Use synchronous I/O operations (i.e. readFileSync in this case). This\n is \"just as bad\" as calling `Queue.pause()` because the query execution is\n paused during the synchronous operation, which will take just as long.\n But, this works, too.\n\nAnd finally, to be clear, you are allowed to do asynchronous calls within the\nquery callback of a transaction. You just need to `commit()` or `rollback()`\nor `pause()` beforehand because the Queue will be empty by the time the\nasynchronous operation completes.\n\n## Questions / Comments / Bugs\n\nPlease feel free to contact me via GitHub, send pull requests, open issues, etc.\n\nI am open to suggestions and criticisms.\n","readmeFilename":"README.md","_id":"mysql-queues@1.0.0","dependencies":{"mysql":">=0.9.5"},"dist":{"shasum":"b6641be424d2c6e647e65e9bb3100f451c7e463a","tarball":"https://registry.npmjs.org/mysql-queues/-/mysql-queues-1.0.0.tgz","integrity":"sha512-XstuFQkfCNcJaxItzEu8d1kS/X4Vr+gL4gnJYEt5slpYVzBJmUo7R9zkpQ2L4T+/VJl8DTG7tSoCD3JtERsq9w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHsVoxQjdc1hlESuZA28eC5ubX8EzeDeZTZMkrVX8r/GAiEA0EjYQd/48/qdC0gRJAUrdjKQ5Uss7xRmTs13i62AdG0="}]},"_from":".","_npmVersion":"1.2.12","_npmUser":{"name":"bminer","email":"miner.blake@gmail.com"},"maintainers":[{"name":"bminer","email":"miner.blake@gmail.com"}],"deprecated":"This library is no longer needed because node-mysql supports transactions"}},"readme":"# node-mysql-queues\n\nAdd your own node-mysql query queues to support transactions and multiple statements\n\nFor use with Node.JS and node-mysql: https://github.com/felixge/node-mysql\n\n## Install\n\n`npm install mysql-queues`\n\n## Usage\n\n```javascript\nvar mysql = require('mysql');\nvar client = mysql.createClient({\n\tuser: 'root',\n\tpassword: 'root'\n});\n//Enable mysql-queues\nvar queues = require('mysql-queues');\nqueues(client);\n//Start running queries as normal...\nclient.query(...);\n\n//Now you want a separate queue?\nvar q = client.createQueue();\nq.query(...); \nq.query(...);\nq.execute();\n\nclient.query(...); //Will not execute until all queued queries completed.\n\n//Now you want a transaction?\nvar trans = client.startTransaction();\ntrans.query(\"INSERT...\", [x, y, z], function(err, info) {\n\tif(err)\n\t\ttrans.rollback();\n\telse\n\t\ttrans.query(\"UPDATE...\", [a, b, c, info.insertId], function(err) {\n\t\t\tif(err)\n\t\t\t\ttrans.rollback();\n\t\t\telse\n\t\t\t\ttrans.commit();\n\t\t});\n});\ntrans.execute();\n//No other queries will get executed until the transaction completes\nclient.query(\"SELECT ...\") //This won't execute until the transaction is COMPLETELY done (including callbacks)\n```\n\n## API\n\n#### `client.query(sql, [params, cb])`\n\nUse normally. Same as node-mysql, except that if a Queue is still pending\ncompletion, this query may be queued for later execution.\n\n#### `client.createQueue()`\n\nCreates a new query Queue.\n\n#### `client.startTransaction()`\n\nCreates a new query Queue with \"START TRANSACTION\" as the first queued query.\nThe Queue object will also have `commit()` and `rollback()` methods.\n\n#### `Queue.query(sql, [params, cb])`\n\nSame as node-mysql. This query will be queued for execution until `execute()`\nis called on the `Queue`.\n\n#### `Queue.execute()`\n\nExecutes all queries that were queued using `Queue.query`. Until all query\n*callbacks* complete, it is guaranteed that all queries in this Queue\nwill be executed in order, with no other queries intermixed.  That is, during\nexecution of this query Queue, all queries executed using `client.query` will\nbe queued until this Queue is empty and all callbacks of this Queue have\nfinished executing. That means that a query added to a Queue can also queue\na query using `Queue.query`, and it will be executed before any `client.query`\ncall. Thus, nested query queueing is supported in query callbacks, allowing\nsupport for transactions and more.\nSee the source code for further documentation.\n\nNote: Once `execute()` is called and all queries have completed, the Queue\nwill be empty again. You may continue to use `Queue.query` and `Queue.execute`\nto queue and execute more queries. However, as noted below, you should\n*never* reuse a Queue created by `client.startTransaction`\n\n#### `Queue.commit()`\n\nAvailable only if this Queue was created with `client.startTransaction`.\nThis queues 'COMMIT' and calls `execute()`\nYou should call either `commit()` or `rollback()` exactly once. Once you call\n`commit()` on this Queue, you should discard it.\n\nIf you do not call `commit()` or `rollback()` and the Queue has completed\nexecution, `commit()` will be called automatically; however, one should\n**NOT** rely on this behavior.\n\n#### `Queue.rollback()`\n\nAvailable only if this Queue was created with `client.startTransaction`.\nThis queues 'ROLLBACK' and calls `execute()`\nYou should call either `commit()` or `rollback()` exactly once. Once you call\n`rollback()` on this Queue, you should discard it.\n","maintainers":[{"name":"bminer","email":"miner.blake@gmail.com"}],"time":{"modified":"2022-06-20T18:18:34.708Z","created":"2011-12-08T21:38:31.276Z","0.2.0":"2011-12-08T21:38:31.500Z","0.2.1":"2011-12-20T15:19:58.521Z","0.2.2":"2011-12-21T15:58:24.083Z","0.2.3":"2011-12-29T21:37:56.499Z","0.3.0":"2011-12-29T19:26:22.168Z","0.3.1":"2011-12-29T21:57:40.661Z","0.3.2":"2012-01-03T03:49:51.535Z","0.3.3":"2012-01-16T18:01:08.743Z","0.3.4":"2012-03-26T17:30:39.356Z","0.3.5":"2012-05-11T00:09:58.812Z","1.0.0":"2013-03-02T02:02:16.824Z"},"author":{"name":"Blake Miner","email":"miner.blake@gmail.com","url":"http://www.blakeminer.com"},"repository":{"type":"git","url":"git://github.com/bminer/node-mysql-queues.git"},"users":{"f124275809":true,"vwal":true}}