UNPKG

periodicjs.core.data

Version:

Core data is the ORM wrapping component of periodicjs.core.controller that provides database adapters for commonly used databases (ie. mongo, sql, postgres). Adapters provide a standard set of methods and options regardless of the type of database and so

2,882 lines (895 loc) 42.1 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: SQL_ADAPTER</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-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Class: SQL_ADAPTER</h1> <section> <header> <h2>SQL_ADAPTER</h2> <div class="class-description"><p>A sequelize SQL specific adapter which provides CRUD methods for a given model</p></div> </header> <article> <div class="container-overview"> <h2>Constructor</h2> <h4 class="name" id="SQL_ADAPTER"><span class="type-signature"></span>new SQL_ADAPTER<span class="signature">(options)</span><span class="type-signature"></span></h4> <div class="description"> <p>Constructor for SQL_Adapter</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>options</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last"><p>Configurable options for the SQL adapter</p> <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>db_connection</code></td> <td class="type"> <span class="param-type">Object</span> | <span class="param-type">Array.&lt;string></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"><p>Either a instantiated instance of Sequelize or the connection details for a instance as an array of ordered arguments or options object</p></td> </tr> <tr> <td class="name"><code>db_connetion.db_name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last"><p>Name of the database (only used if instantiating a new Sequelize instance)</p></td> </tr> <tr> <td class="name"><code>db_connetion.db_user</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last"><p>Username for the database (only used if instantiating a new Sequelize instance)</p></td> </tr> <tr> <td class="name"><code>db_connetion.db_password</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last"><p>Password for the database (only used if instantiating a new Sequelize instance)</p></td> </tr> <tr> <td class="name"><code>db_connetion.db_options</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last"><p>Options for connection to the database ie. port, hostname (only used if instantiating a new Sequelize instance)</p></td> </tr> <tr> <td class="name"><code>docid</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> "id" </td> <td class="description last"><p>Specifies the field which should be queried by default for .load</p></td> </tr> <tr> <td class="name"><code>model</code></td> <td class="type"> <span class="param-type">Object</span> | <span class="param-type">Array.&lt;Object></span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"><p>Either a registered sequelize model or if options.model is an Array it will be treated as the arguments to define a sequelize model</p></td> </tr> <tr> <td class="name"><code>sort</code></td> <td class="type"> <span class="param-type">Object</span> | <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> "createdat DESC" </td> <td class="description last"><p>Specifies default sort logic for .query and .search queries</p></td> </tr> <tr> <td class="name"><code>limit</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> 500 </td> <td class="description last"><p>Specifies a default limit to the total documents returned in a .query and .search queries</p></td> </tr> <tr> <td class="name"><code>skip</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> 0 </td> <td class="description last"><p>Specifies a default amount of documents to skip in a .query and .search queries</p></td> </tr> <tr> <td class="name"><code>population</code></td> <td class="type"> <span class="param-type">Object</span> | <span class="param-type">Array.&lt;Object></span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> [] </td> <td class="description last"><p>Optional population configuration for documents returned in .load and .search queries (see sequelize include for proper formatting)</p></td> </tr> <tr> <td class="name"><code>fields</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> </td> <td class="description last"><p>Optional configuration for limiting fields that are returned in .load and .search queries</p></td> </tr> <tr> <td class="name"><code>pagelength</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> 15 </td> <td class="description last"><p>Specifies max number of documents that should appear in each sub-set for pagination</p></td> </tr> <tr> <td class="name"><code>track_changes</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> true </td> <td class="description last"><p>Sets default track changes behavior for udpates</p></td> </tr> <tr> <td class="name"><code>xss_whitelist</code></td> <td class="type"> <span class="param-type">Array.&lt;string></span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>Configuration for XSS whitelist package. If false XSS whitelisting will be ignored</p></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="adapters_sql.js.html">adapters/sql.js</a>, <a href="adapters_sql.js.html#line503">line 503</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="create"><span class="type-signature"></span>create<span class="signature">(options<span class="signature-attributes">opt</span>, cb<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Object}</span></h4> <div class="description"> <p>Create method for adapter see _CREATE for more details</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</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="attributes"> &lt;optional><br> </td> <td class="default"> {} </td> <td class="description last"><p>Configurable options for create</p></td> </tr> <tr> <td class="name"><code>cb</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>Callback argument. When cb is not passed function returns a Promise</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="adapters_sql.js.html">adapters/sql.js</a>, <a href="adapters_sql.js.html#line651">line 651</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Returns a Promise when cb argument is not passed</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> <h4 class="name" id="delete"><span class="type-signature"></span>delete<span class="signature">(options<span class="signature-attributes">opt</span>, cb<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Object}</span></h4> <div class="description"> <p>Delete method for adapter see _DELETE and _DELETED for more details</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</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="attributes"> &lt;optional><br> </td> <td class="default"> {} </td> <td class="description last"><p>Configurable options for create</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>return_deleted</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="description last"><p>If true delete method will return the deleted document</p></td> </tr> </tbody> </table> </td> </tr> <tr> <td class="name"><code>cb</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>Callback argument. When cb is not passed function returns a Promise</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="adapters_sql.js.html">adapters/sql.js</a>, <a href="adapters_sql.js.html#line663">line 663</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Returns a Promise when cb argument is not passed</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> <h4 class="name" id="load"><span class="type-signature"></span>load<span class="signature">(options<span class="signature-attributes">opt</span>, cb<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Object}</span></h4> <div class="description"> <p>Load method for adapter see _LOAD for more details</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</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="attributes"> &lt;optional><br> </td> <td class="default"> {} </td> <td class="description last"><p>Configurable options for load</p></td> </tr> <tr> <td class="name"><code>cb</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>Callback argument. When cb is not passed function returns a Promise</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="adapters_sql.js.html">adapters/sql.js</a>, <a href="adapters_sql.js.html#line627">line 627</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Returns a Promise when cb argument is not passed</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> <h4 class="name" id="query"><span class="type-signature"></span>query<span class="signature">(options<span class="signature-attributes">opt</span>, cb<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Object}</span></h4> <div class="description"> <p>Query method for adapter see _QUERY and _QUERY_WITH_PAGINATION for more details</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</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="attributes"> &lt;optional><br> </td> <td class="default"> {} </td> <td class="description last"><p>Configurable options for query</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>paginate</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="description last"><p>When true query will return data in a paginated form</p></td> </tr> </tbody> </table> </td> </tr> <tr> <td class="name"><code>cb</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>Callback argument. When cb is not passed function returns a Promise</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="adapters_sql.js.html">adapters/sql.js</a>, <a href="adapters_sql.js.html#line594">line 594</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Returns a Promise when cb argument is not passed</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> <h4 class="name" id="raw"><span class="type-signature"></span>raw<span class="signature">(options, cb)</span><span class="type-signature"> &rarr; {Object}</span></h4> <div class="description"> <p>Raw query method for adapter see _RAW for more details</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Default</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="default"> </td> <td class="description last"><p>Configurable options for raw query</p></td> </tr> <tr> <td class="name"><code>cb</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="default"> false </td> <td class="description last"><p>Callback argument. When cb is not passed function returns a Promise</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="adapters_sql.js.html">adapters/sql.js</a>, <a href="adapters_sql.js.html#line674">line 674</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Returns a Promise when cb argument is not passed</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> <h4 class="name" id="search"><span class="type-signature"></span>search<span class="signature">(options<span class="signature-attributes">opt</span>, cb<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Object}</span></h4> <div class="description"> <p>Search method for adapter see _SEARCH for more details</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</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="attributes"> &lt;optional><br> </td> <td class="default"> {} </td> <td class="description last"><p>Configurable options for query</p></td> </tr> <tr> <td class="name"><code>cb</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>Callback argument. When cb is not passed function returns a Promise</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="adapters_sql.js.html">adapters/sql.js</a>, <a href="adapters_sql.js.html#line605">line 605</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Returns a Promise when cb argument is not passed</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> <h4 class="name" id="stream"><span class="type-signature"></span>stream<span class="signature">(options<span class="signature-attributes">opt</span>, cb<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Object}</span></h4> <div class="description"> <p>Stream method for adapter see _STREAM for more details</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</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="attributes"> &lt;optional><br> </td> <td class="default"> {} </td> <td class="description last"><p>Configurable options for stream</p></td> </tr> <tr> <td class="name"><code>cb</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>Callback argument. When cb is not passed function returns a Promise</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="adapters_sql.js.html">adapters/sql.js</a>, <a href="adapters_sql.js.html#line616">line 616</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Returns a Promise when cb argument is not passed</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> <h4 class="name" id="sync"><span class="type-signature"></span>sync<span class="signature">(options<span class="signature-attributes">opt</span>, cb<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Object}</span></h4> <div class="description"> <p>Sync defined sequelize models with SQL db</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</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="attributes"> &lt;optional><br> </td> <td class="default"> {} </td> <td class="description last"><p>Configurable options for sequelize sync method</p></td> </tr> <tr> <td class="name"><code>cb</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>Callback argument. When cb is not passed function returns a Promise</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="adapters_sql.js.html">adapters/sql.js</a>, <a href="adapters_sql.js.html#line563">line 563</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Returns a Promise when cb argument is not passed</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> <h4 class="name" id="update"><span class="type-signature"></span>update<span class="signature">(options<span class="signature-attributes">opt</span>, cb<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Object}</span></h4> <div class="description"> <p>Update method for adapter see _UPDATE, _UPDATED and _UPDATE_ALL for more details</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</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="attributes"> &lt;optional><br> </td> <td class="default"> {} </td> <td class="description last"><p>Configurable options for update</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>return_updated</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="description last"><p>If true update method will return the updated document instead of an update status message</p></td> </tr> <tr> <td class="name"><code>multi</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="description last"><p>If true a multiple document update will be perfomed</p></td> </tr> </tbody> </table> </td> </tr> <tr> <td class="name"><code>cb</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>Callback argument. When cb is not passed function returns a Promise</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="adapters_sql.js.html">adapters/sql.js</a>, <a href="adapters_sql.js.html#line640">line 640</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>Returns a Promise when cb argument is not passed</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="CURSOR.html">CURSOR</a></li><li><a href="DB_ADAPTER_INTERFACE.html">DB_ADAPTER_INTERFACE</a></li><li><a href="LOKI_ADAPTER.html">LOKI_ADAPTER</a></li><li><a href="MONGO_ADAPTER.html">MONGO_ADAPTER</a></li><li><a href="SQL_ADAPTER.html">SQL_ADAPTER</a></li></ul><h3>Global</h3><ul><li><a href="global.html#_CREATE">_CREATE</a></li><li><a href="global.html#_DELETE">_DELETE</a></li><li><a href="global.html#_DELETED">_DELETED</a></li><li><a href="global.html#_LOAD">_LOAD</a></li><li><a href="global.html#_QUERY">_QUERY</a></li><li><a href="global.html#_QUERY_WITH_PAGINATION">_QUERY_WITH_PAGINATION</a></li><li><a href="global.html#_RAW">_RAW</a></li><li><a href="global.html#_SEARCH">_SEARCH</a></li><li><a href="global.html#_STREAM">_STREAM</a></li><li><a href="global.html#_UPDATE">_UPDATE</a></li><li><a href="global.html#_UPDATE_ALL">_UPDATE_ALL</a></li><li><a href="global.html#_UPDATED">_UPDATED</a></li><li><a href="global.html#defaultError">defaultError</a></li><li><a href="global.html#defaultSuccess">defaultSuccess</a></li><li><a href="global.html#EXAMPLE">EXAMPLE</a></li><li><a href="global.html#GENERATE_PATCH">GENERATE_PATCH</a></li><li><a href="global.html#GENERATE_PUT">GENERATE_PUT</a></li><li><a href="global.html#GENERATE_SELECT">GENERATE_SELECT</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Apr 07 2017 09:04:28 GMT-0400 (EDT) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>