{"name":"mysql2","version":"2.0.0-alpha1","keywords":["mysql","client","server"],"author":{"name":"Andrey Sidorov","email":"sidorares@yandex.ru"},"license":"MIT","_id":"mysql2@2.0.0-alpha1","maintainers":[{"name":"iarna","email":"me@re-becca.org"},{"name":"sidorares","email":"sidorares@yandex.com"},{"name":"sushantdhiman","email":"sushantdhiman@outlook.com"}],"homepage":"https://github.com/sidorares/node-mysql2#readme","bugs":{"url":"https://github.com/sidorares/node-mysql2/issues"},"dist":{"shasum":"cb76b874c4c24471334cfebb874ebed9a2a6afe5","tarball":"http://registry-npm.ywwl.com/mysql2/download/mysql2-2.0.0-alpha1.tgz","fileCount":73,"integrity":"sha512-E1S97AZ7uuDycWzjzmSsPlp6Lgxd83XKFGyi8AOurFBmjC70XmqvSNigJfnioOjkh4ghsEe1m8nobx/PANi/FQ==","signatures":[{"sig":"MEQCIAkErAVwJMba0o64oMQW2iKFyUfqrPAW9+iaSSek0vcfAiBBdjgr4VHIXbLQItcdKYXDNs2EGZTJ/jcKPvoEfkW+dA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":420970,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdoyCwCRA9TVsSAnZWagAA/7kP/j9KTr5TjaXuSjYtO60I\nHNwRu4grejYtm07K7WtRxVqdSJVzg+azW1Gt1CiP5FhmtQ+VdlcPh/CR6qjv\n9qMVJtHTexYY+G5La0+13hEF0Ha3t9sKlcHtVpLwOh35LqmWYFvyc4Ei0AW+\nLa9y+t+zlecRTInzGCluw2EB3P58SeeWEAf2mBCNy3v965tLSDgB5FfCOMPa\nHiu6qsI8UYWMGeOaf5XXgDi07LIjyXMIHwbu6ksF3mrjuySm6Xue7c1glzCs\nblcEw/MqNGTOb9LEodWvjm37f4C9gaujaMP6yOS1aEPM3mGdyz8so2wXDlmx\nEqLEVi4O+CHO2geMOvkZw9w18GYYtYJgdywvyaePnDfqviqRKwnjXRynRDdQ\nfUEsM+T6Ekzs+5cQL+wEDqa3c5tteRyC21NETzoXt8AJxwgptRo9Dl5bClvg\nTiZmHm1upP0sLuUXVlFrEAJnPyK+nj6+1XgE8s65qFCmywuGjHLkLEy4FAo9\nENI86203lVIJ/KQrrcx0LnHyLna5300fNasjQvm8D4puCMn6uhw/Xt0hC05y\nv8qJ7eXO5ugnBA9qiMnZQJYAw9SzWGE0HtCW6Hfgnz5boFEPcIYY2txSotlD\nD+AefaatZne+J72QkNZdSZUNDE+4kXjSDHzHqc0axPLxqt4ibB5c28dE78vx\n23E/\r\n=b2Xx\r\n-----END PGP SIGNATURE-----\r\n","size":117043,"noattachment":false,"key":"/mysql2/-/mysql2-2.0.0-alpha1.tgz"},"main":"index.js","readme":"## Node MySQL 2\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/sidorares/node-mysql2.svg)](https://greenkeeper.io/)\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Node.js Version][node-version-image]][node-version-url]\n[![Linux Build][travis-image]][travis-url]\n[![Windows Build][appveyor-image]][appveyor-url]\n[![License][license-image]][license-url]\n\n> MySQL client for Node.js with focus on performance. Supports prepared statements, non-utf8 encodings, binary log protocol, compression, ssl [much more](https://github.com/sidorares/node-mysql2/tree/master/documentation)\n\n__Table of contents__\n\n  - [History and Why MySQL2](#history-and-why-mysql2)\n  - [Installation](#installation)\n  - [First Query](#first-query)\n  - [Using Prepared Statements](#using-prepared-statements)\n  - [Using connection pools](#using-connection-pools)\n  - [Using Promise Wrapper](#using-promise-wrapper)\n  - [API and Configuration](#api-and-configuration)\n  - [Documentation](#documentation)\n  - [Acknowledgements](#acknowledgements)\n  - [Contributing](#contributing)\n\n## History and Why MySQL2\n\nMySQL2 project is a continuation of [MySQL-Native][mysql-native]. Protocol parser code was rewritten from scratch and api changed to match popular [mysqljs/mysql][node-mysql]. MySQL2 team is working together with [mysqljs/mysql][node-mysql] team to factor out shared code and move it under [mysqljs][node-mysql] organisation.\n\nMySQL2 is mostly API compatible with [mysqljs][node-mysql] and supports majority of features. MySQL2 also offers these additional features\n\n - Faster / Better Performance\n - [Prepared Statements](https://github.com/sidorares/node-mysql2/tree/master/documentation/Prepared-Statements.md)\n - MySQL Binary Log Protocol\n - [MySQL Server](https://github.com/sidorares/node-mysql2/tree/master/documentation/MySQL-Server.md)\n - Extended support for Encoding and Collation\n - [Promise Wrapper](https://github.com/sidorares/node-mysql2/tree/master/documentation/Promise-Wrapper.md)\n - Compression\n - SSL and [Authentication Switch](https://github.com/sidorares/node-mysql2/tree/master/documentation/Authentication-Switch.md)\n - [Custom Streams](https://github.com/sidorares/node-mysql2/tree/master/documentation/Extras.md)\n - [Pooling](#using-connection-pools)\n\n## Installation\n\nMySQL2 is free from native bindings and can be installed on Linux, Mac OS or Windows without any issues.\n\n```bash\nnpm install --save mysql2\n```\n\n## First Query\n\n```js\n// get the client\nconst mysql = require('mysql2');\n\n// create the connection to database\nconst connection = mysql.createConnection({\n  host: 'localhost',\n  user: 'root',\n  database: 'test'\n});\n\n// simple query\nconnection.query(\n  'SELECT * FROM `table` WHERE `name` = \"Page\" AND `age` > 45',\n  function(err, results, fields) {\n    console.log(results); // results contains rows returned by server\n    console.log(fields); // fields contains extra meta data about results, if available\n  }\n);\n\n// with placeholder\nconnection.query(\n  'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n  ['Page', 45],\n  function(err, results) {\n    console.log(results);\n  }\n);\n```\n\n## Using Prepared Statements\n\nWith MySQL2 you also get the prepared statements. With prepared statements MySQL doesn't have to prepare plan for same query everytime, this results in better performance. If you don't know why they are important, please check these discussions\n\n- [How prepared statements can protect from SQL Injection attacks](http://stackoverflow.com/questions/8263371/how-can-prepared-statements-protect-from-sql-injection-attacks)\n\nMySQL provides `execute` helper which will prepare and query the statement. You can also manually prepare / unprepare statement with `prepare` / `unprepare` methods.\n\n```js\n// get the client\nconst mysql = require('mysql2');\n\n// create the connection to database\nconst connection = mysql.createConnection({\n  host: 'localhost',\n  user: 'root',\n  database: 'test'\n});\n\n// execute will internally call prepare and query\nconnection.execute(\n  'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n  ['Rick C-137', 53],\n  function(err, results, fields) {\n    console.log(results); // results contains rows returned by server\n    console.log(fields); // fields contains extra meta data about results, if available\n\n    // If you execute same statement again, it will be picked from a LRU cache\n    // which will save query preparation time and give better performance\n  }\n);\n```\n\n## Using connection pools\n\nConnection pools help reduce the time spent connecting to the MySQL server by reusing a previous connection, leaving them open instead of closing when you are done with them.\n\nThis improves the latency of queries as you avoid all of the overhead that comes with establishing a new connection.\n\n```js\n// get the client\nconst mysql = require('mysql2');\n\n// Create the connection pool. The pool-specific settings are the defaults\nconst pool = mysql.createPool({\n  host: 'localhost',\n  user: 'root',\n  database: 'test',\n  waitForConnections: true,\n  connectionLimit: 10,\n  queueLimit: 0\n});\n```\nThe pool does not create all connections upfront but creates them on demand until the connection limit is reached.\n\nYou can use the pool in the same way as connections (using `pool.query()` and `pool.execute()`):\n```js\n// For pool initialization, see above\npool.query(\"SELECT field FROM atable\", function(err, rows, fields) {\n   // Connection is automatically released when query resolves\n})\n```\n\nAlternatively, there is also the possibility of manually acquiring a connection from the pool and returning it later:\n```js\n// For pool initialization, see above\npool.getConnection(function(err, conn) {\n   // Do something with the connection\n   conn.query(/* ... */);\n   // Don't forget to release the connection when finished!\n   pool.releaseConnection(conn);\n})\n```\n\n## Using Promise Wrapper\n\nMySQL2 also support Promise API. Which works very well with ES7 async await.\n\n<!--eslint-disable-next-block-->\n```js\nasync function main() {\n  // get the client\n  const mysql = require('mysql2/promise');\n  // create the connection\n  const connection = await mysql.createConnection({host:'localhost', user: 'root', database: 'test'});\n  // query database\n  const [rows, fields] = await connection.execute('SELECT * FROM `table` WHERE `name` = ? AND `age` > ?', ['Morty', 14]);\n}\n```\n\nMySQL2 use default `Promise` object available in scope. But you can choose which `Promise` implementation you want to use\n\n<!--eslint-disable-next-block-->\n```js\n// get the client\nconst mysql = require('mysql2/promise');\n\n// get the promise implementation, we will use bluebird\nconst bluebird = require('bluebird');\n\n// create the connection, specify bluebird as Promise\nconst connection = await mysql.createConnection({host:'localhost', user: 'root', database: 'test', Promise: bluebird});\n\n// query database\nconst [rows, fields] = await connection.execute('SELECT * FROM `table` WHERE `name` = ? AND `age` > ?', ['Morty', 14]);\n```\n\nMySQL2 also exposes a .promise() function on Pools, so you can create a promise/non-promise connections from the same pool\n```js\nasync function main() {\n  // get the client\n  const mysql = require('mysql2');\n  // create the pool\n  const pool = mysql.createPool({host:'localhost', user: 'root', database: 'test'});\n  // now get a Promise wrapped instance of that pool\n  const promisePool = pool.promise();\n  // query database using promises\n  const [rows,fields] = await promisePool.query(\"SELECT 1\");\n```\n\nMySQL2 exposes a .promise() function on Connections, to \"upgrade\" an existing non-promise connection to use promise\n```js\n// get the client\nconst mysql = require('mysql2');\n// create the connection\nconst con = mysql.createConnection(\n  {host:'localhost', user: 'root', database: 'test'}\n);\ncon.promise().query(\"SELECT 1\")\n  .then( ([rows,fields]) => {\n    console.log(rows);\n  })\n  .catch(console.log)\n  .then( () => con.end());\n```\n\n## API and Configuration\n\nMySQL2 is mostly API compatible with [Node MySQL][node-mysql]. You should check their API documentation to see all available API options.\n\nIf you find any incompatibility with [Node MySQL][node-mysql], Please report via Issue tracker. We will fix reported incompatibility on priority basis.\n\n## Documentation\n\nYou can find more detailed documentation [here](https://github.com/sidorares/node-mysql2/tree/master/documentation). You should also check various code [examples](https://github.com/sidorares/node-mysql2/tree/master/examples) to understand advanced concepts.\n\n## Acknowledgements\n\n  - Internal protocol is written by @sidorares [MySQL-Native](https://github.com/sidorares/nodejs-mysql-native)\n  - Constants, SQL parameters interpolation, Pooling, `ConnectionConfig` class taken from [node-mysql](https://github.com/mysqljs/mysql)\n  - SSL upgrade code based on @TooTallNate [code](https://gist.github.com/TooTallNate/848444)\n  - Secure connection / compressed connection api flags compatible to [MariaSQL](https://github.com/mscdex/node-mariasql/) client.\n  - [Contributors](https://github.com/sidorares/node-mysql2/graphs/contributors)\n\n## Contributing\n\nWant to improve something in `node-mysql2`. Please check [Contributing.md](https://github.com/sidorares/node-mysql2/blob/master/Contributing.md) for detailed instruction on how to get started.\n\n\n[npm-image]: https://img.shields.io/npm/v/mysql2.svg\n[npm-url]: https://npmjs.org/package/mysql2\n[node-version-image]: http://img.shields.io/node/v/mysql2.svg\n[node-version-url]: http://nodejs.org/download/\n[travis-image]: https://img.shields.io/travis/sidorares/node-mysql2/master.svg?label=linux\n[travis-url]: https://travis-ci.org/sidorares/node-mysql2\n[appveyor-image]: https://img.shields.io/appveyor/ci/sidorares/node-mysql2/master.svg?label=windows\n[appveyor-url]: https://ci.appveyor.com/project/sidorares/node-mysql2\n[downloads-image]: https://img.shields.io/npm/dm/mysql2.svg\n[downloads-url]: https://npmjs.org/package/mysql2\n[license-url]: https://github.com/sidorares/node-mysql2/blob/master/License\n[license-image]: https://img.shields.io/npm/l/mysql2.svg?maxAge=2592000\n[node-mysql]: https://github.com/mysqljs/mysql\n[mysql-native]: https://github.com/sidorares/nodejs-mysql-native\n","engines":{"node":">= 8.0"},"gitHead":"e868bcc8b46fc793e87fa2e36076f283e6260433","scripts":{"lint":"npm run lint:docs && npm run lint:code","test":"npm run lint && npm run test:raw","prettier":"prettier --single-quote --trailing-comma none --write \"{lib,examples,test}/**/*.js\"","test:raw":"node ./test/run.js","benchmark":"./benchmarks/run-unit.js","lint:code":"eslint index.js promise.js \"lib/**/*.js\" \"test/**/*.js\" \"benchmarks/**/*.js\"","lint:docs":"eslint Contributing.md \"documentation/**/*.md\" \"examples/*.js\"","precommit":"lint-staged","wait-port":"wait-on","eslint-check":"eslint --print-config .eslintrc | eslint-config-prettier-check","prettier:docs":"prettier-markdown README.md documentation/*"},"_npmUser":{"name":"sidorares","email":"sidorares@yandex.com"},"repository":{"url":"git+https://github.com/sidorares/node-mysql2.git","type":"git"},"_npmVersion":"6.9.0","description":"fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS","directories":{"example":"examples"},"lint-staged":{"*.js":["prettier --single-quote --trailing-comma none --write","git add"]},"_nodeVersion":"10.16.3","dependencies":{"long":"^4.0.0","denque":"^1.4.1","cardinal":"^2.1.1","lru-cache":"^5.1.1","seq-queue":"^0.0.5","sqlstring":"^2.3.1","iconv-lite":"^0.5.0","generate-function":"^2.3.1","named-placeholders":"^1.1.2"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"urun":"0.0.8","husky":"^3.0.4","utest":"0.0.8","eslint":"^6.2.2","prettier":"^1.18.2","progress":"^2.0.3","portfinder":"^1.0.23","assert-diff":"^2.0.2","lint-staged":"^9.2.5","prettier-markdown":"^0.1.6","error-stack-parser":"^2.0.3","is-async-supported":"^1.2.0","eslint-config-prettier":"^6.1.0","eslint-plugin-markdown":"^1.0.0","eslint-plugin-async-await":"0.0.0"},"_npmOperationalInternal":{"tmp":"tmp/mysql2_2.0.0-alpha1_1570971823846_0.6601762468518217","host":"s3://npm-registry-packages"},"publish_time":1570971824010,"_cnpm_publish_time":1570971824010,"dist-tags":{"beta":"2.0.0-alpha1","canary":"3.24.6-canary.8c068ef","latest":"3.24.6","next":"3.0.0-rc.1"}}