{"versions":{"0.1.0":{"name":"gaussdb-pool","version":"0.1.0","description":"Connection pool for GaussDB","main":"index.js","exports":{".":{"import":"./esm/index.mjs","require":"./index.js","default":"./index.js"}},"directories":{"test":"test"},"scripts":{"test":" node_modules/.bin/mocha"},"repository":{"type":"git","url":"git+ssh://git@github.com/HuaweiCloudDeveloper/gaussdb-node.git","directory":"packages/gaussdb-pool"},"keywords":["gaussdb","pool","database"],"author":{"name":"Brian M. Carlson"},"license":"MIT","devDependencies":{"bluebird":"3.7.2","co":"4.6.0","expect.js":"0.3.1","lodash":"^4.17.11","mocha":"^10.5.2"},"peerDependencies":{"gaussdb":">=0.1.0"},"gitHead":"cf38482bc7ae4573c2b9e3a24387feb7ce6b6fb2","bugs":{"url":"https://github.com/HuaweiCloudDeveloper/gaussdb-node/issues"},"homepage":"https://github.com/HuaweiCloudDeveloper/gaussdb-node#readme","_id":"gaussdb-pool@0.1.0","_nodeVersion":"20.19.2","_npmVersion":"lerna/7.4.2/node@v20.19.2+x64 (linux)","dist":{"integrity":"sha512-PEnrqEhL582Dl4kftlRrYqTjaSFXtUOUeWIz9jnL9am50Zz9tUU68nNoatknClCnlziF9jlok3B6O7YYAYiq+w==","shasum":"9d97fcad90afb796c6cc507e346f406c65b18fec","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/gaussdb-pool/-/gaussdb-pool-0.1.0.tgz","fileCount":5,"unpackedSize":29352,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDochf6w2t9KB0ysk+ScKfYkmkkFMsHQL3EnQvTkzEAngIgXTZchZ2XJBYWnX/I2t6PmFmoxAiE+5AnVO6VlLqTJ6k="}],"size":9635},"_npmUser":{"name":"anonymous","email":"happygame1024@gmail.com"},"maintainers":[{"name":"anonymous","email":"happygame1024@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/gaussdb-pool_0.1.0_1749539100522_0.32698292164276466"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-06-10T07:05:00.745Z","publish_time":1749539100745,"_source_registry_name":"default","contributors":[]},"0.1.1":{"name":"gaussdb-pool","version":"0.1.1","description":"Connection pool for GaussDB","main":"index.js","exports":{".":{"import":"./esm/index.mjs","require":"./index.js","default":"./index.js"}},"directories":{"test":"test"},"scripts":{"test":" node_modules/.bin/mocha"},"repository":{"type":"git","url":"git+ssh://git@github.com/HuaweiCloudDeveloper/gaussdb-node.git","directory":"packages/gaussdb-pool"},"keywords":["gaussdb","pool","database"],"author":{"name":"Brian M. Carlson"},"license":"MIT","devDependencies":{"bluebird":"3.7.2","co":"4.6.0","expect.js":"0.3.1","lodash":"^4.17.11","mocha":"^10.5.2"},"peerDependencies":{"gaussdb":">=0.1.0"},"gitHead":"5507b29fee23efcf710c9411b2d28c51e61b6fc1","bugs":{"url":"https://github.com/HuaweiCloudDeveloper/gaussdb-node/issues"},"homepage":"https://github.com/HuaweiCloudDeveloper/gaussdb-node#readme","_id":"gaussdb-pool@0.1.1","_nodeVersion":"20.19.2","_npmVersion":"lerna/7.4.2/node@v20.19.2+x64 (linux)","dist":{"integrity":"sha512-ChRpesv1aOtOMIrGiTN2WK0uA2ZfBZBIevoWNt91uQQLZQunHZKX8xqSfLSdrYDOR+q8A9ENthVOBrMSuFYYZA==","shasum":"4efce808d968b48df42b43fc3a1beff4bce10976","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/gaussdb-pool/-/gaussdb-pool-0.1.1.tgz","fileCount":5,"unpackedSize":28651,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDWNDWv7nabJhDAEGy+jTeEBirWNbFceq7HhOGmQ26/JAiEAp1SRPJgQzN71nywZhLJIcRrXf4iC3MCESh4rWP8USS8="}],"size":9280},"_npmUser":{"name":"anonymous","email":"happygame1024@gmail.com","actor":{"name":"happygame","email":"happygame1024@gmail.com","type":"user"}},"maintainers":[{"name":"anonymous","email":"happygame1024@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/gaussdb-pool_0.1.1_1751009885639_0.9795466007352802"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-06-27T07:38:05.835Z","publish_time":1751009885835,"_source_registry_name":"default","contributors":[]},"0.2.0":{"name":"gaussdb-pool","version":"0.2.0","description":"Connection pool for GaussDB","main":"index.js","exports":{".":{"import":"./esm/index.mjs","require":"./index.js","default":"./index.js"}},"directories":{"test":"test"},"scripts":{"test":" node_modules/.bin/mocha"},"repository":{"type":"git","url":"git@github.com:HuaweiCloudDeveloper/gaussdb-node.git","directory":"packages/gaussdb-pool"},"keywords":["gaussdb","pool","database"],"author":"Brian M. Carlson","license":"MIT","devDependencies":{"bluebird":"3.7.2","co":"4.6.0","expect.js":"0.3.1","lodash":"^4.17.11","mocha":"^10.5.2"},"peerDependencies":{"gaussdb":">=0.1.0"},"gitHead":"f94b11adc5a52d2964a0a4c6d865691861f900cb","_nodeVersion":"20.19.3","_npmVersion":"lerna/8.2.2/node@v20.19.3+x64 (linux)","_id":"gaussdb-pool@0.2.0","dist":{"integrity":"sha512-1oSVXZjG6YlRLiuhtoxyNNTF/foCXnN/ccUny6199Q0MWcl4VDSaGlhCa/7iEot826cfwz+Xg1QD7Ujkomoe6Q==","shasum":"01f9bca9cb637ca35a72a5b65fc6e01dfa48f2d5","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/gaussdb-pool/-/gaussdb-pool-0.2.0.tgz","fileCount":5,"unpackedSize":28651,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDV2TKARisKc/eoRi3TAO/NuOoXiynQrp9jk0VlglDgXwIgeNoWKywiDp2+k+22hWWX6wccvDmtJQztbBOCi4f5Bk8="}],"size":9284},"_npmUser":{"name":"anonymous","email":"happygame1024@gmail.com","actor":{"name":"happygame","email":"happygame1024@gmail.com","type":"user"}},"maintainers":[{"name":"anonymous","email":"happygame1024@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/gaussdb-pool_0.2.0_1751100932331_0.3396670729040723"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-06-28T08:55:32.578Z","publish_time":1751100932578,"_source_registry_name":"default","contributors":[]},"0.2.1":{"name":"gaussdb-pool","version":"0.2.1","description":"Connection pool for GaussDB","main":"index.js","exports":{".":{"import":"./esm/index.mjs","require":"./index.js","default":"./index.js"}},"directories":{"test":"test"},"scripts":{"test":" node_modules/.bin/mocha"},"repository":{"type":"git","url":"git@github.com:HuaweiCloudDeveloper/gaussdb-node.git","directory":"packages/gaussdb-pool"},"keywords":["gaussdb","pool","database"],"author":"Brian M. Carlson","license":"MIT","devDependencies":{"bluebird":"3.7.2","co":"4.6.0","expect.js":"0.3.1","lodash":"^4.17.11","mocha":"^10.5.2"},"peerDependencies":{"gaussdb-node":">=0.2.0"},"gitHead":"debbf9ede742e0c9adcb34755350acfd1b27a73b","_nodeVersion":"20.19.3","_npmVersion":"lerna/8.2.3/node@v20.19.3+x64 (linux)","_id":"gaussdb-pool@0.2.1","dist":{"integrity":"sha512-2G/KFdly2MhNssqWi0T8praDsnzCnAoCcXKOiS4vkcmOVNKLsYWbxPjOdfwIyNdihsQ8P/QpHAbpF0dybFTRXg==","shasum":"c05437b6dd63e1d6fa88a9f2c05c1b48fbd83d0b","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/gaussdb-pool/-/gaussdb-pool-0.2.1.tgz","fileCount":5,"unpackedSize":28304,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGSfGjf3m3t+l4EW/PgEtMcF9a9Sbuj6e2FYpqGLozNuAiAEUeR2JGqsVWnec7TKe7/eI4+jzAYfcQjjYhM9jvpEEQ=="}],"size":9184},"_npmUser":{"name":"anonymous","email":"happygame1024@gmail.com","actor":{"name":"happygame","email":"happygame1024@gmail.com","type":"user"}},"maintainers":[{"name":"anonymous","email":"happygame1024@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/gaussdb-pool_0.2.1_1751510744646_0.6701042236011634"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-07-03T02:45:44.857Z","publish_time":1751510744857,"_source_registry_name":"default","contributors":[]}},"dist-tags":{"latest":"0.2.1"},"name":"gaussdb-pool","time":{"created":"2025-06-10T07:06:00.487Z","modified":"2025-07-03T03:16:11.572Z","0.1.0":"2025-06-10T07:05:00.745Z","0.1.1":"2025-06-27T07:38:05.835Z","0.2.0":"2025-06-28T08:55:32.578Z","0.2.1":"2025-07-03T02:45:44.857Z"},"readme":"# gaussdb-pool\n<!-- TODO: 构建后恢复 -->\n<!-- [![Build Status](https://travis-ci.org/brianc/node-pg-pool.svg?branch=master)](https://travis-ci.org/brianc/node-pg-pool) -->\n\nA connection pool for gaussdb-node\n\n## install\n```sh\nnpm i gaussdb-pool gaussdb\n```\n\n## use\n\n### create\n\nto use gaussdb-pool you must first create an instance of a pool\n\n```js\nconst Pool = require('gaussdb-pool')\n\n// by default the pool uses the same\n// configuration as whatever `gaussdb` version you have installed\nconst pool = new Pool()\n\n// you can pass properties to the pool\n// these properties are passed unchanged to both the gaussdb-node Client constructor\n// and the node-pool (https://github.com/coopernurse/node-pool) constructor\n// allowing you to fully configure the behavior of both\nconst pool2 = new Pool({\n  database: 'gaussdb-node',\n  user: 'tset',\n  password: 'secret!',\n  port: 5432,\n  ssl: true,\n  max: 20, // set pool max size to 20\n  idleTimeoutMillis: 1000, // close idle clients after 1 second\n  connectionTimeoutMillis: 1000, // return an error after 1 second if connection could not be established\n  maxUses: 7500, // close (and replace) a connection after it has been used 7500 times (see below for discussion)\n})\n\n```\n\n##### Note:\nThe Pool constructor does not support passing a Database URL as the parameter. To use gaussdb-pool on heroku, for example, you need to parse the URL into a config object. Here is an example of how to parse a Database URL.\n\n```js\nconst Pool = require('gaussdb-pool');\nconst url = require('url')\n\nconst params = url.parse(process.env.DATABASE_URL);\nconst auth = params.auth.split(':');\n\nconst config = {\n  user: auth[0],\n  password: auth[1],\n  host: params.hostname,\n  port: params.port,\n  database: params.pathname.split('/')[1],\n  ssl: true\n};\n\nconst pool = new Pool(config);\n\n/*\n  Transforms, 'gaussdb://DBuser:secret@DBHost:#####/myDB', into\n  config = {\n    user: 'DBuser',\n    password: 'secret',\n    host: 'DBHost',\n    port: '#####',\n    database: 'myDB',\n    ssl: true\n  }\n*/\n``` \n\n### acquire clients with a promise\n\ngaussdb-pool supports a fully promise-based api for acquiring clients\n\n```js\nconst pool = new Pool()\npool.connect().then(client => {\n  client.query('select $1::text as name', ['gaussdb-pool']).then(res => {\n    client.release()\n    console.log('hello from', res.rows[0].name)\n  })\n  .catch(e => {\n    client.release()\n    console.error('query error', e.message, e.stack)\n  })\n})\n```\n\n### plays nice with async/await\n\nthis ends up looking much nicer if you're using [co](https://github.com/tj/co) or async/await:\n\n```js\n// with async/await\n(async () => {\n  const pool = new Pool()\n  const client = await pool.connect()\n  try {\n    const result = await client.query('select $1::text as name', ['brianc'])\n    console.log('hello from', result.rows[0])\n  } finally {\n    client.release()\n  }\n})().catch(e => console.error(e.message, e.stack))\n\n// with co\nco(function * () {\n  const client = yield pool.connect()\n  try {\n    const result = yield client.query('select $1::text as name', ['brianc'])\n    console.log('hello from', result.rows[0])\n  } finally {\n    client.release()\n  }\n}).catch(e => console.error(e.message, e.stack))\n```\n\n### your new favorite helper method\n\nbecause its so common to just run a query and return the client to the pool afterward gaussdb-pool has this built-in:\n\n```js\nconst pool = new Pool()\nconst time = await pool.query('SELECT NOW()')\nconst name = await pool.query('select $1::text as name', ['brianc'])\nconsole.log(name.rows[0].name, 'says hello at', time.rows[0].now)\n```\n\nyou can also use a callback here if you'd like:\n\n```js\nconst pool = new Pool()\npool.query('SELECT $1::text as name', ['brianc'], function (err, res) {\n  console.log(res.rows[0].name) // brianc\n})\n```\n\n__pro tip:__ unless you need to run a transaction (which requires a single client for multiple queries) or you\nhave some other edge case like [streaming rows](https://github.com/brianc/node-pg-query-stream) or using a [cursor](https://github.com/brianc/node-pg-cursor)\nyou should almost always just use `pool.query`.  Its easy, it does the right thing :tm:, and wont ever forget to return\nclients back to the pool after the query is done.\n\n### drop-in backwards compatible\n\ngaussdb-pool still and will always support the traditional callback api for acquiring a client:\n\n```js\nconst pool = new Pool()\npool.connect((err, client, done) => {\n  if (err) return done(err)\n\n  client.query('SELECT $1::text as name', ['gaussdb-pool'], (err, res) => {\n    done()\n    if (err) {\n      return console.error('query error', err.message, err.stack)\n    }\n    console.log('hello from', res.rows[0].name)\n  })\n})\n```\n\n### shut it down\n\nWhen you are finished with the pool if all the clients are idle the pool will close them after `config.idleTimeoutMillis` and your app\nwill shutdown gracefully.  If you don't want to wait for the timeout you can end the pool as follows:\n\n```js\nconst pool = new Pool()\nconst client = await pool.connect()\nconsole.log(await client.query('select now()'))\nclient.release()\nawait pool.end()\n```\n\n### a note on instances\n\nThe pool should be a __long-lived object__ in your application.  Generally you'll want to instantiate one pool when your app starts up and use the same instance of the pool throughout the lifetime of your application.  If you are frequently creating a new pool within your code you likely don't have your pool initialization code in the correct place.  Example:\n\n```js\n// assume this is a file in your program at ./your-app/lib/db.js\n\n// correct usage: create the pool and let it live\n// 'globally' here, controlling access to it through exported methods\nconst pool = new gaussdb.Pool()\n\n// this is the right way to export the query method\nmodule.exports.query = (text, values) => {\n  console.log('query:', text, values)\n  return pool.query(text, values)\n}\n\n// this would be the WRONG way to export the connect method\nmodule.exports.connect = () => {\n  // notice how we would be creating a pool instance here\n  // every time we called 'connect' to get a new client?\n  // that's a bad thing & results in creating an unbounded\n  // number of pools & therefore connections\n  const aPool = new gaussdb.Pool()\n  return aPool.connect()\n}\n```\n\n### events\n\nEvery instance of a `Pool` is an event emitter.  These instances emit the following events:\n\n#### error\n\nEmitted whenever an idle client in the pool encounters an error.  This is common when your Gaussdb server shuts down, reboots, or a network partition otherwise causes it to become unavailable while your pool has connected clients.\n\nExample:\n\n```js\nconst Pool = require('gaussdb-pool')\nconst pool = new Pool()\n\n// attach an error handler to the pool for when a connected, idle client\n// receives an error by being disconnected, etc\npool.on('error', function(error, client) {\n  // handle this in the same way you would treat process.on('uncaughtException')\n  // it is supplied the error as well as the idle client which received the error\n})\n```\n\n#### connect\n\nFired whenever the pool creates a __new__ `gaussdb.Client` instance and successfully connects it to the backend.\n\nExample:\n\n```js\nconst Pool = require('gaussdb-pool')\nconst pool = new Pool()\n\nconst count = 0\n\npool.on('connect', client => {\n  client.count = count++\n})\n\npool\n  .connect()\n  .then(client => {\n    return client\n      .query('SELECT $1::int AS \"clientCount\"', [client.count])\n      .then(res => console.log(res.rows[0].clientCount)) // outputs 0\n      .then(() => client)\n  })\n  .then(client => client.release())\n\n```\n\n#### acquire\n\nFired whenever a client is acquired from the pool\n\nExample:\n\nThis allows you to count the number of clients which have ever been acquired from the pool.\n\n```js\nconst Pool = require('gaussdb-pool')\nconst pool = new Pool()\n\nconst acquireCount = 0\npool.on('acquire', function (client) {\n  acquireCount++\n})\n\nconst connectCount = 0\npool.on('connect', function () {\n  connectCount++\n})\n\nfor (let i = 0; i < 200; i++) {\n  pool.query('SELECT NOW()')\n}\n\nsetTimeout(function () {\n  console.log('connect count:', connectCount) // output: connect count: 10\n  console.log('acquire count:', acquireCount) // output: acquire count: 200\n}, 100)\n\n```\n\n### environment variables\n\ngaussdb-pool & gaussdb-node support some of the same environment variables as `psql` supports.  The most common are:\n\n```\nGAUSSDATABASE=my_db\nGAUSSUSER=username\nGAUSSPASSWORD=\"my awesome password\"\nGAUSSPORT=5432\nGAUSSSSLMODE=require\n```\n\n\n## bring your own promise\n\nIn versions of node `<=0.12.x` there is no native promise implementation available globally.  You can polyfill the promise globally like this:\n\n```js\n// first run `npm install promise-polyfill --save\nif (typeof Promise == 'undefined') {\n  global.Promise = require('promise-polyfill')\n}\n```\n\nYou can use any other promise implementation you'd like.  The pool also allows you to configure the promise implementation on a per-pool level:\n\n```js\nconst bluebirdPool = new Pool({\n  Promise: require('bluebird')\n})\n```\n\n__please note:__ in node `<=0.12.x` the pool will throw if you do not provide a promise constructor in one of the two ways mentioned above.  In node `>=4.0.0` the pool will use the native promise implementation by default; however, the two methods above still allow you to \"bring your own.\"\n\n## maxUses and read-replica autoscaling (e.g. AWS Aurora)\n\nThe maxUses config option can help an application instance rebalance load against a replica set that has been auto-scaled after the connection pool is already full of healthy connections.\n\nThe mechanism here is that a connection is considered \"expended\" after it has been acquired and released `maxUses` number of times.  Depending on the load on your system, this means there will be an approximate time in which any given connection will live, thus creating a window for rebalancing.\n\nImagine a scenario where you have 10 app instances providing an API running against a replica cluster of 3 that are accessed via a round-robin DNS entry.  Each instance runs a connection pool size of 20.  With an ambient load of 50 requests per second, the connection pool will likely fill up in a few minutes with healthy connections.\n\nIf you have weekly bursts of traffic which peak at 1,000 requests per second, you might want to grow your replicas to 10 during this period.  Without setting `maxUses`, the new replicas will not be adopted by the app servers without an intervention -- namely, restarting each in turn in order to build up new connection pools that are balanced against all the replicas.  Adding additional app server instances will help to some extent because they will adopt all the replicas in an even way, but the initial app servers will continue to focus additional load on the original replicas.\n\nThis is where the `maxUses` configuration option comes into play.  Setting `maxUses` to 7500 will ensure that over a period of 30 minutes or so the new replicas will be adopted as the pre-existing connections are closed and replaced with new ones, thus creating a window for eventual balance.\n\nYou'll want to test based on your own scenarios, but one way to make a first guess at `maxUses` is to identify an acceptable window for rebalancing and then solve for the value:\n\n```\nmaxUses = rebalanceWindowSeconds * totalRequestsPerSecond / numAppInstances / poolSize\n```\n\nIn the example above, assuming we acquire and release 1 connection per request and we are aiming for a 30 minute rebalancing window:\n\n```\nmaxUses = rebalanceWindowSeconds * totalRequestsPerSecond / numAppInstances / poolSize\n   7200 =        1800            *          1000          /        10       /    25\n```\n\n## tests\n\nTo run tests clone the repo, `npm i` in the working dir, and then run `npm test`\n\n\n## license\n\nThe MIT License (MIT)\nCopyright (c) 2016 Brian M. Carlson\nCopyright (c) 2025 happy-game\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","users":{}}