UNPKG

node-pg-connection-pool

Version:

Connection pool for node-postgres with generic-pool support

1,877 lines (473 loc) 21.8 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>PgPool - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="PgPool.html">PgPool</a><ul class='methods'><li data-type='method'><a href="PgPool.html#acquire">acquire</a></li><li data-type='method'><a href="PgPool.html#availableCount">availableCount</a></li><li data-type='method'><a href="PgPool.html#destroy">destroy</a></li><li data-type='method'><a href="PgPool.html#drain">drain</a></li><li data-type='method'><a href="PgPool.html#getName">getName</a></li><li data-type='method'><a href="PgPool.html#getPgOptions">getPgOptions</a></li><li data-type='method'><a href="PgPool.html#getPoolOptions">getPoolOptions</a></li><li data-type='method'><a href="PgPool.html#getPoolSize">getPoolSize</a></li><li data-type='method'><a href="PgPool.html#pendingCount">pendingCount</a></li><li data-type='method'><a href="PgPool.html#query">query</a></li><li data-type='method'><a href="PgPool.html#release">release</a></li><li data-type='method'><a href="PgPool.html#status">status</a></li></ul></li></ul> </nav> <div id="main"> <h1 class="page-title">PgPool</h1> <section> <header> <h2> PgPool </h2> </header> <article> <div class="container-overview"> <h4 class="name" id="PgPool"><span class="type-signature"></span>new PgPool<span class="signature">(options)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line68">line 68</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>Accepts properties [&quot;name&quot;, &quot;pgOptions&quot;, &quot;poolOptions&quot;, &quot;logger&quot;]</p> <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>Name your pool</p></td> </tr> <tr> <td class="name"><code>pgOptions</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>opts from <a href="https://github.com/brianc/node-postgres/wiki/Client#parameters">node-postgres/wiki/Client#parameters</a></p></td> </tr> <tr> <td class="name"><code>pgNative</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>Use native bindings</p></td> </tr> <tr> <td class="name"><code>poolOptions</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>opts from <a href="https://github.com/coopernurse/node-pool#createpool">node-pool#createpool</a></p></td> </tr> <tr> <td class="name"><code>logger</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>Inject your custom logger</p></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="acquire"><span class="type-signature"></span>acquire<span class="signature">(priority, db)</span><span class="type-signature"> &rarr; {promise}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line187">line 187</a> </li></ul></dd> </dl> <div class="description"> <p>Acquire a Postgres connection and use an optional priority.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>priority</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"><p>priority list number</p></td> </tr> <tr> <td class="name"><code>db</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"><p>Use the db with range {0-16}</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>Promise resolve with the connection or Error</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">promise</span> </dd> </dl> <h4 class="name" id="availableCount"><span class="type-signature"></span>availableCount<span class="signature">()</span><span class="type-signature"> &rarr; {number}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line270">line 270</a> </li></ul></dd> </dl> <div class="description"> <p>Returns available connections count of the pool</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>available connections count of the pool</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="destroy"><span class="type-signature"></span>destroy<span class="signature">(client)</span><span class="type-signature"> &rarr; {promise}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line216">line 216</a> </li></ul></dd> </dl> <div class="description"> <p>Destroy a Postgres connection.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>client</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>Postgres connection</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>Promise</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">promise</span> </dd> </dl> <h4 class="name" id="drain"><span class="type-signature"></span>drain<span class="signature">()</span><span class="type-signature"> &rarr; {promise}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line225">line 225</a> </li></ul></dd> </dl> <div class="description"> <p>Drains the connection pool and call the callback id provided.</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>Promise</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">promise</span> </dd> </dl> <h4 class="name" id="getName"><span class="type-signature"></span>getName<span class="signature">()</span><span class="type-signature"> &rarr; {string}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line234">line 234</a> </li></ul></dd> </dl> <div class="description"> <p>Returns factory.name for this pool</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>Name of the pool</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="getPgOptions"><span class="type-signature"></span>getPgOptions<span class="signature">()</span><span class="type-signature"> &rarr; {object}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line243">line 243</a> </li></ul></dd> </dl> <div class="description"> <p>Returns this.pgOptions for this pool</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>Postgres options given</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> <h4 class="name" id="getPoolOptions"><span class="type-signature"></span>getPoolOptions<span class="signature">()</span><span class="type-signature"> &rarr; {object}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line252">line 252</a> </li></ul></dd> </dl> <div class="description"> <p>Returns this.poolOptions for this pool</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>pool options given</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> <h4 class="name" id="getPoolSize"><span class="type-signature"></span>getPoolSize<span class="signature">()</span><span class="type-signature"> &rarr; {number}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line261">line 261</a> </li></ul></dd> </dl> <div class="description"> <p>Returns size of the pool</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>size of the pool</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="pendingCount"><span class="type-signature"></span>pendingCount<span class="signature">()</span><span class="type-signature"> &rarr; {number}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line279">line 279</a> </li></ul></dd> </dl> <div class="description"> <p>Returns pending connections count of the pool</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>pending connections count of the pool</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="query"><span class="type-signature"></span>query<span class="signature">(queryText, arrayValues)</span><span class="type-signature"> &rarr; {promise}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line160">line 160</a> </li></ul></dd> </dl> <div class="description"> <p>Run Postgres query <a href="https://github.com/brianc/node-postgres/wiki/Client#querystring-querytext-array-values-optional-function-callback-query">Client#querytext-arrayvalues</a></p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>queryText</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>sql query</p></td> </tr> <tr> <td class="name"><code>arrayValues</code></td> <td class="type"> <span class="param-type">array</span> </td> <td class="description last"><p>array values</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>Promise resolve with the result or Error</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">promise</span> </dd> </dl> <h4 class="name" id="release"><span class="type-signature"></span>release<span class="signature">(client)</span><span class="type-signature"> &rarr; {promise}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line206">line 206</a> </li></ul></dd> </dl> <div class="description"> <p>Release a Postgres connection to the pool.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>client</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>Postgres connection</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>Promise</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">promise</span> </dd> </dl> <h4 class="name" id="status"><span class="type-signature"></span>status<span class="signature">()</span><span class="type-signature"> &rarr; {object}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="index.js.html">index.js</a>, <a href="index.js.html#line288">line 288</a> </li></ul></dd> </dl> <div class="description"> <p>Returns pool status and stats</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>pool status and stats</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> </article> </section> </div> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>