sharp-db
Version:
Classes for running SQL and building select queries for MySQL in Node
11,611 lines • 167 kB
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Db - 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="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.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>
<li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="DataBroker.html">DataBroker</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="DataBroker.html#cleanup">cleanup</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="DataBroker.html#created_and_modified">created_and_modified</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="DataBroker.html#createdAndModified">createdAndModified</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="DataBroker.html#delete">delete</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="DataBroker.html#insert">insert</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Db.html">Db</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#.destroyAll">destroyAll</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#.endAll">endAll</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#.factory">factory</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#.withInstance">withInstance</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#beginTransaction">beginTransaction</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#bindArgs">bindArgs</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#commit">commit</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#connect">connect</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#connectOnce">connectOnce</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#delete">delete</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#deleteFrom">deleteFrom</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#destroy">destroy</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#emit">emit</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#emitError">emitError</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#end">end</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#escape">escape</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#escapeLike">escapeLike</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#escapeQuoteless">escapeQuoteless</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#exportAsSql">exportAsSql</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#insert">insert</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#insertExtended">insertExtended</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#insertInto">insertInto</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#insertIntoOnDuplicateKeyUpdate">insertIntoOnDuplicateKeyUpdate</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#multiQuery">multiQuery</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#query">query</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#quote">quote</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#rollback">rollback</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#select">select</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#selectByKey">selectByKey</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#selectExists">selectExists</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#selectFirst">selectFirst</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#selectFrom">selectFrom</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#selectGrouped">selectGrouped</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#selectHash">selectHash</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#selectId">selectId</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#selectIndexed">selectIndexed</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#selectList">selectList</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#selectOrCreate">selectOrCreate</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#selectOrCreateId">selectOrCreateId</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#selectUuid">selectUuid</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#selectValue">selectValue</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#startTransaction">startTransaction</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#tpl">tpl</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#update">update</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Db.html#updateTable">updateTable</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="DbEvent.html">DbEvent</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Parser.html">Parser</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_extractSubqueries">_extractSubqueries</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleConditions">_handleConditions</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleCrossJoin">_handleCrossJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleFrom">_handleFrom</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleFullJoin">_handleFullJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleFullOuterJoin">_handleFullOuterJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleGroupBy">_handleGroupBy</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleHaving">_handleHaving</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleInnerJoin">_handleInnerJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleLeftJoin">_handleLeftJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleLeftOuterJoin">_handleLeftOuterJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleLimit">_handleLimit</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleOffset">_handleOffset</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleOrderBy">_handleOrderBy</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleRightJoin">_handleRightJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleRightOuterJoin">_handleRightOuterJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleSelect">_handleSelect</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_handleWhere">_handleWhere</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_injectSubqueries">_injectSubqueries</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_split">_split</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#_stripComments">_stripComments</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Parser.html#parse">parse</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Select.html">Select</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#._extractBindingName">_extractBindingName</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#.init">init</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#.parse">parse</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#_conditions">_conditions</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#_isEntirelyDigits">_isEntirelyDigits</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#_isEntirelyDigitsNoZeros">_isEntirelyDigitsNoZeros</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#_isPlaceholder">_isPlaceholder</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#_spliceChildData">_spliceChildData</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#_spliceSiblingData">_spliceSiblingData</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#bind">bind</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#column">column</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#columns">columns</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#crossJoin">crossJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#escape">escape</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#escapeLike">escapeLike</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#escapeQuoteless">escapeQuoteless</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#fetch">fetch</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#fetchFirst">fetchFirst</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#fetchGrouped">fetchGrouped</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#fetchHash">fetchHash</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#fetchIndexed">fetchIndexed</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#fetchList">fetchList</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#fetchValue">fetchValue</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#foundRows">foundRows</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#from">from</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#fullJoin">fullJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#fullOuterJoin">fullOuterJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#getClone">getClone</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#getFoundRowsQuery">getFoundRowsQuery</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#getFoundRowsSql">getFoundRowsSql</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#groupBy">groupBy</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#having">having</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#innerJoin">innerJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#join">join</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#leftJoin">leftJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#leftOuterJoin">leftOuterJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#limit">limit</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#normalized">normalized</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#offset">offset</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#option">option</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#orderBy">orderBy</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#orHaving">orHaving</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#orWhere">orWhere</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#page">page</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#parse">parse</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#reset">reset</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#rightJoin">rightJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#rightOuterJoin">rightOuterJoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#sortField">sortField</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#table">table</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#tables">tables</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#toBoundSql">toBoundSql</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#toString">toString</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#unbind">unbind</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#unjoin">unjoin</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#where">where</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#whereBetween">whereBetween</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#withChildData">withChildData</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Select.html#withSiblingData">withSiblingData</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Ssh.html">Ssh</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Ssh.html#end">end</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Ssh.html#tunnelTo">tunnelTo</a></span></li>
</nav>
<div id="main">
<h1 class="page-title">Db</h1>
<section>
<header>
<h2>
Db
</h2>
<div class="class-description"><p>Simple database class for mysql</p></div>
</header>
<article>
<div class="container-overview">
<div class="section-method">
<h2>Constructor</h2>
<h4 class="name" id="Db"><span class="type-signature"></span>new Db<span class="signature">(config<span class="signature-attributes">opt</span>, sshConfig<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Specify connection details for MySQL and optionally SSH</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line14">line 14</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="https://github.com/mysqljs/mysql#connection-options">https://github.com/mysqljs/mysql#connection-options</a></li>
<li><a href="https://github.com/mscdex/ssh2#client-methods">https://github.com/mscdex/ssh2#client-methods</a></li>
</ul>
</dd>
</dl>
<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>config</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
</td>
<td class="description last">
<p>MySQL connection details such as host, login, password, encoding, database</p>
</td>
</tr>
<tr>
<td class="name"><code>sshConfig</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
null
</td>
<td class="description last">
<p>SSH connection details including host, port, user, privateKey</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3 class="subsection-title">Members</h3>
<div class="section-members">
<h4 class="name" id=".instances"><span class="type-signature">(static) </span>instances<span class="type-signature"> :Array</span></h4>
<div class="description">
<p>A list of all the Db instances that have been created</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line1062">line 1062</a>
</li></ul></dd>
</dl>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><code>Array</code></span>
</li>
</ul>
</div>
<div class="section-members">
<h4 class="name" id="config"><span class="type-signature"></span>config<span class="type-signature"> :Object</span></h4>
<div class="description">
<p>The config used for this instance</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line29">line 29</a>
</li></ul></dd>
</dl>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><code>Object</code></span>
</li>
</ul>
</div>
<div class="section-members">
<h4 class="name" id="connection"><span class="type-signature"></span>connection<span class="type-signature"> :Object</span></h4>
<div class="description">
<p>The mysql2 library connection object</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line118">line 118</a>
</li></ul></dd>
</dl>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><code>Object</code></span>
</li>
</ul>
</div>
<div class="section-members">
<h4 class="name" id="ssh"><span class="type-signature"></span>ssh<span class="type-signature"> :<a href="Ssh.html">Ssh</a></span></h4>
<div class="description">
<p>The Ssh instance for tunnelling</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line44">line 44</a>
</li></ul></dd>
</dl>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><code><a href="Ssh.html">Ssh</a></code></span>
</li>
</ul>
</div>
<h3 class="subsection-title">Methods</h3>
<div class="section-method">
<h4 class="name" id=".destroyAll"><span class="type-signature">(static) </span>destroyAll<span class="signature">()</span><span class="type-signature"> → {<a href="Db.html">Db</a>}</span></h4>
<div class="description">
<p>Destroy all connections to the database</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line205">line 205</a>
</li></ul></dd>
</dl>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code><a href="Db.html">Db</a></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id=".endAll"><span class="type-signature">(static) </span>endAll<span class="signature">()</span><span class="type-signature"> → {Promise}</span></h4>
<div class="description">
<p>Close all connections to the database</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line197">line 197</a>
</li></ul></dd>
</dl>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise</code></span>
</dd>
</dl>
<div class="param-desc">
<p>Resolves when all connections have been closed</p>
</div>
</div>
</div>
<div class="section-method">
<h4 class="name" id=".factory"><span class="type-signature">(static) </span>factory<span class="signature">(config<span class="signature-attributes">opt</span>, sshConfig<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {<a href="Db.html">Db</a>}</span></h4>
<div class="description">
<p>Create a new QuickDb instance or return the last used one.
Specify connection details for MySQL and optionally SSH</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line96">line 96</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="https://github.com/mysqljs/mysql#connection-options">https://github.com/mysqljs/mysql#connection-options</a></li>
<li><a href="https://github.com/mscdex/ssh2#client-methods">https://github.com/mscdex/ssh2#client-methods</a></li>
</ul>
</dd>
</dl>
<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>config</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
</td>
<td class="description last">
<p>MySQL connection details such as host, login, password, encoding, database</p>
</td>
</tr>
<tr>
<td class="name"><code>sshConfig</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
null
</td>
<td class="description last">
<p>SSH connection details including host, port, user, privateKey</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code><a href="Db.html">Db</a></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id=".withInstance"><span class="type-signature">(async, static) </span>withInstance<span class="signature">(config<span class="signature-attributes">opt</span>, sshConfig<span class="signature-attributes">opt</span>, handler)</span><span class="type-signature"> → {Promise.<(Error|*)>}</span></h4>
<div class="description">
<p>Run the given handler by passing a new database instance. Three signatures:
Db.withInstance(handler)
Db.withInstance(mysqlConfig, handler)
Db.withInstance(mysqlConfig, sshConfig, handler)</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line1036">line 1036</a>
</li></ul></dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>config</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">
<p>The mysql connection information (or omit to read from env)</p>
</td>
</tr>
<tr>
<td class="name"><code>sshConfig</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">
<p>The ssh config information (or omit to read from env)</p>
</td>
</tr>
<tr>
<td class="name"><code>handler</code></td>
<td class="type">
<span class="param-type"><code>function</code></span>
</td>
<td class="attributes">
</td>
<td class="description last">
<p>The function to pass the Db instance to</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<(Error|*)></code></span>
</dd>
</dl>
</div>
<div class="section-examples">
<h5>Example</h5>
<pre class="prettyprint"><code>const addresses = await Db.withInstance(async db => {
const sql = 'SELECT * FROM animals WHERE type = "cat"';
const { results: cats } = await db.select(sql);
const homes = await findHomes(cats);
return {
homes: homes.map(home => home.address);
};
});</code></pre>
</div>
</div>
<div class="section-method">
<h4 class="name" id="beginTransaction"><span class="type-signature"></span>beginTransaction<span class="signature">()</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>run START TRANSACTION</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line821">line 821</a>
</li></ul></dd>
</dl>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="bindArgs"><span class="type-signature"></span>bindArgs<span class="signature">(sql, args)</span><span class="type-signature"> → {Object}</span></h4>
<div class="description">
<p>Bind an arguments to a query</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL with bound values replaced</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line865">line 865</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>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The base SQL query</p>
</td>
</tr>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>A value, an object with key/value paris, or an array of values to bind</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Object</code></span>
</dd>
</dl>
</div>
<div class="section-examples">
<h5>Example</h5>
<pre class="prettyprint"><code>db.select('SELECT * FROM users WHERE id = ?', 100);
db.bindArgs('SELECT * FROM users WHERE id = ?', 100); // SELECT * FROM users WHERE id = '100'
db.select('SELECT * FROM users WHERE id = :id', { id: 100 });
db.bindArgs('SELECT * FROM users WHERE id = :id', { id: 100 }); // SELECT * FROM users WHERE id = '100'</code></pre>
</div>
</div>
<div class="section-method">
<h4 class="name" id="commit"><span class="type-signature"></span>commit<span class="signature">()</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>run COMMIT</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line839">line 839</a>
</li></ul></dd>
</dl>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="connect"><span class="type-signature">(async) </span>connect<span class="signature">(overrides<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Make a new connection to MySQL</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line109">line 109</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="https://github.com/mysqljs/mysql#connection-options">https://github.com/mysqljs/mysql#connection-options</a></li>
</ul>
</dd>
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>overrides</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">
<p>Additional connection params</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
<div class="param-desc">
<p>The mysql connection object</p>
</div>
</div>
</div>
<div class="section-method">
<h4 class="name" id="connectOnce"><span class="type-signature">(async) </span>connectOnce<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Make a new connection to MySQL if not already connected</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line136">line 136</a>
</li></ul></dd>
</dl>
</div>
<div class="section-method">
<h4 class="name" id="delete"><span class="type-signature">(async) </span>delete<span class="signature">(sql)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Run the given DELETE statement</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>changedRows</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The number of rows affected by the statement</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line501">line 501</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>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The SQL to run</p>
</td>
</tr>
<tr>
<td class="name"><code>...bindVars</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>The values to bind to the each question mark or named binding</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="deleteFrom"><span class="type-signature">(async) </span>deleteFrom<span class="signature">(table, where, limit)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Construct a DELETE query and run</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>affectedRows</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The number of rows matching the WHERE criteria</p></td>
</tr>
<tr>
<td class="name"><code>changedRows</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The number of rows affected by the statement</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line748">line 748</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>SqlBuilder#buildWheres</li>
</ul>
</dd>
</dl>
<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>table</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="default">
</td>
<td class="description last">
<p>The name of the table from which to delete</p>
</td>
</tr>
<tr>
<td class="name"><code>where</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="default">
</td>
<td class="description last">
<p>WHERE conditions on which to delete - see SqlBuilder#buildWheres</p>
</td>
</tr>
<tr>
<td class="name"><code>limit</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="default">
null
</td>
<td class="description last">
<p>Limit deletion to this many records</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="destroy"><span class="type-signature"></span>destroy<span class="signature">()</span><span class="type-signature"> → {<a href="Db.html">Db</a>}</span></h4>
<div class="description">
<p>Destroy the connection to the database</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line177">line 177</a>
</li></ul></dd>
</dl>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code><a href="Db.html">Db</a></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="emit"><span class="type-signature"></span>emit<span class="signature">(type, data)</span><span class="type-signature"> → {<a href="DbEvent.html">DbEvent</a>}</span></h4>
<div class="description">
<p>Emit an event and associated data</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line55">line 55</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>type</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The event name</p>
</td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>Data to send with event</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code><a href="DbEvent.html">DbEvent</a></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="emitError"><span class="type-signature"></span>emitError<span class="signature">(subtype, error, data)</span><span class="type-signature"> → {<a href="DbEvent.html">DbEvent</a>}</span></h4>
<div class="description">
<p>Emit a dbError event and associated data</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line74">line 74</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>subtype</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the event that would have been called in a success case</p>
</td>
</tr>
<tr>
<td class="name"><code>error</code></td>
<td class="type">
<span class="param-type"><code>Error</code></span>
</td>
<td class="description last">
<p>The error that was raised</p>
</td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>Data to send with event</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code><a href="DbEvent.html">DbEvent</a></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="end"><span class="type-signature"></span>end<span class="signature">()</span><span class="type-signature"> → {Promise}</span></h4>
<div class="description">
<p>Close this connection to the database</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line146">line 146</a>
</li></ul></dd>
</dl>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise</code></span>
</dd>
</dl>
<div class="param-desc">
<p>Resolves when connection has been closed</p>
</div>
</div>
</div>
<div class="section-method">
<h4 class="name" id="escape"><span class="type-signature"></span>escape<span class="signature">(value)</span><span class="type-signature"> → {String}</span></h4>
<div class="description">
<p>Escape a value for use in a raw query and surround with apostrophes</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line910">line 910</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>value</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>The value to escape</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>String</code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="escapeLike"><span class="type-signature"></span>escapeLike<span class="signature">(infix, value)</span><span class="type-signature"> → {String}</span></h4>
<div class="description">
<p>Get the proper escaping for a LIKE or NOT LIKE clause</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line933">line 933</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>infix</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>One of ?% or %?% or %? or ?</p>
</td>
</tr>
<tr>
<td class="name"><code>value</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The value to search for</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>String</code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="escapeQuoteless"><span class="type-signature"></span>escapeQuoteless<span class="signature">(value)</span><span class="type-signature"> → {String}</span></h4>
<div class="description">
<p>Escape a value for use in a raw query without apostrophes</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line919">line 919</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>value</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Number</code></span>
|
<span class="param-type"><code>Boolean</code></span>
|
<span class="param-type"><code>null</code></span>
</td>
<td class="description last">
<p>The value to escape</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>String</code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="exportAsSql"><span class="type-signature">(async) </span>exportAsSql<span class="signature">(table, where, options)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Construct INSERT statements suitable for a backup</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<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>limit</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
0
</td>
<td class="description last"><p>Limit export to this many records</p></td>
</tr>
<tr>
<td class="name"><code>chunkSize</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
250
</td>
<td class="description last"><p>If > 0, restrict INSERT STATEMENTS to a maximum of this many records</p></td>
</tr>
<tr>
<td class="name"><code>discardIds</code></td>
<td class="type">
<span class="param-type"><code>Boolean</code></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
false
</td>
<td class="description last"><p>If true, columns selected as "id" will have a NULL value</p></td>
</tr>
<tr>
<td class="name"><code>disableForeignKeyChecks</code></td>
<td class="type">
<span class="param-type"><code>Boolean</code></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
false
</td>
<td class="description last"><p>If true, add statements to disable and re-enable foreign key checks</p></td>
</tr>
<tr>
<td class="name"><code>lockTables</code></td>
<td class="type">
<span class="param-type"><code>Boolean</code></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
false
</td>
<td class="description last"><p>If true, add statements to lock and unlock tables</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last"><p>The exported SQL</p></td>
</tr>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last"><p>The SQL that was executed to fetch records</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last"><p>Details on the fields fetched</p></td>
</tr>
<tr>
<td class="name"><code>affectedRows</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last"><p>The number of rows matching the WHERE criteria</p></td>
</tr>
<tr>
<td class="name"><code>chunks</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last"><p>The number of chunks of rows</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line771">line 771</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>SqlBuilder#buildWheres</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>table</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the table from which to fetch records</p>
</td>
</tr>
<tr>
<td class="name"><code>where</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>WHERE conditions on which to fetch records - see SqlBuilder#buildWheres</p>
</td>
</tr>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>Additional options</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="insert"><span class="type-signature">(async) </span>insert<span class="signature">(sql)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Run the given INSERT statement</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>insertId</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The id of the last inserted record</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line439">line 439</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>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The SQL to run</p>
</td>
</tr>
<tr>
<td class="name"><code>...bindVars</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>The values to bind to the each question mark or named binding</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="insertExtended"><span class="type-signature"></span>insertExtended<span class="signature">(table, rows)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Build an INSERT statement and run it</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>insertId</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The id of the last inserted record</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line716">line 716</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>table</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the table</p>
</td>
</tr>
<tr>
<td class="name"><code>rows</code></td>
<td class="type">
<span class="param-type"><code>Array</code></span>
</td>
<td class="description last">
<p>An Array of objects, each with column-value pairs to insert</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="insertInto"><span class="type-signature"></span>insertInto<span class="signature">(table, insert)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Build an INSERT statement and run it</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>insertId</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The id of the last inserted record</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line683">line 683</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>table</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the table</p>
</td>
</tr>
<tr>
<td class="name"><code>insert</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>column-value pairs to insert</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="insertIntoOnDuplicateKeyUpdate"><span class="type-signature">(async) </span>insertIntoOnDuplicateKeyUpdate<span class="signature">(table, insert, update)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Run an "INSERT INTO ... ON DUPLICATE KEY UPDATE" query where
if a key conflicts, update the given fields</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>insertId</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The id of the last inserted or updated record</p></td>
</tr>
<tr>
<td class="name"><code>affectedRows</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The number of rows matching the WHERE criteria</p></td>
</tr>
<tr>
<td class="name"><code>changedRows</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The number of rows affected by the statement</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line699">line 699</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>table</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the table</p>
</td>
</tr>
<tr>
<td class="name"><code>insert</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>An array with column => value pairs for insertion</p>
</td>
</tr>
<tr>
<td class="name"><code>update</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>An array with column => value pairs for update</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="multiQuery"><span class="type-signature">(async) </span>multiQuery<span class="signature">(sql)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Run multiple statements separated by semicolon</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Array</code></span>
</td>
<td class="description last"><p>One element for every statement in the query</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line246">line 246</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>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The sql to run</p>
</td>
</tr>
<tr>
<td class="name"><code>...bindVars</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>Values to bind to the sql placeholders</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="query"><span class="type-signature">(async) </span>query<span class="signature">(sql)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Run a statement of any type</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Array</code></span>
</td>
<td class="description last"><p>The result rows</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line219">line 219</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>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The sql to run</p>
</td>
</tr>
<tr>
<td class="name"><code>...bindVars</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>Values to bind to the sql placeholders</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="quote"><span class="type-signature"></span>quote<span class="signature">(identifier)</span><span class="type-signature"> → {*}</span></h4>
<div class="description">
<p>Escape an identifier such as a table or column</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line957">line 957</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>identifier</code></td>
<td class="type">
</td>
<td class="description last">
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>*</code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="rollback"><span class="type-signature"></span>rollback<span class="signature">()</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>run ROLLBACK</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line848">line 848</a>
</li></ul></dd>
</dl>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="select"><span class="type-signature">(async) </span>select<span class="signature">(sql)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Return result rows for the given SELECT statement</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Array</code></span>
</td>
<td class="description last"><p>The result rows</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line262">line 262</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>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The SQL to run</p>
</td>
</tr>
<tr>
<td class="name"><code>...bindVars</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>The values to bind to the each question mark or named binding</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="selectByKey"><span class="type-signature"></span>selectByKey<span class="signature">(table, column, value)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Select the record with the given column value</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
|
<span class="param-type"><code>undefined</code></span>
</td>
<td class="description last"><p>The result row or undefined</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line550">line 550</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>table</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the table from which to select</p>
</td>
</tr>
<tr>
<td class="name"><code>column</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the column from which to select</p>
</td>
</tr>
<tr>
<td class="name"><code>value</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The value of the record for that column</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="selectExists"><span class="type-signature">(async) </span>selectExists<span class="signature">(sql)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Run the given SELECT statement wrapped in a SELECT EXISTS query</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Boolean</code></span>
</td>
<td class="description last"><p>True if any records match query</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line419">line 419</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>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The SQL to run</p>
</td>
</tr>
<tr>
<td class="name"><code>...bindVars</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>The values to bind to the each question mark or named binding</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="selectFirst"><span class="type-signature">(async) </span>selectFirst<span class="signature">(sql)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Return first result row for the given SELECT statement</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
|
<span class="param-type"><code>undefined</code></span>
</td>
<td class="description last"><p>The result row or undefined</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line378">line 378</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>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The SQL to run</p>
</td>
</tr>
<tr>
<td class="name"><code>...bindVars</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>The values to bind to the each question mark or named binding</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="selectFrom"><span class="type-signature"></span>selectFrom<span class="signature">(table, fields, criteria, extra)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Build a SELECT statement and return result rows</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Array</code></span>
</td>
<td class="description last"><p>The result rows</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line535">line 535</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>SqlBuilder#buildWhere</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>table</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the table</p>
</td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array</code></span>
</td>
<td class="description last">
<p>An array of field names to select</p>
</td>
</tr>
<tr>
<td class="name"><code>criteria</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>Params to construct the WHERE clause - see SqlBuilder#buildWhere</p>
</td>
</tr>
<tr>
<td class="name"><code>extra</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>Additional raw SQL such as GROUP BY, ORDER BY, or LIMIT</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="selectGrouped"><span class="type-signature">(async) </span>selectGrouped<span class="signature">(groupField, sql)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Return records all grouped by one of the column's values</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last"><p>Result rows grouped by groupField</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line330">line 330</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>groupField</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the field to group by</p>
</td>
</tr>
<tr>
<td class="name"><code>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The SQL to run</p>
</td>
</tr>
<tr>
<td class="name"><code>...bindVars</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>The values to bind to the each question mark or named binding</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="selectHash"><span class="type-signature">(async) </span>selectHash<span class="signature">(sql)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Return result array as col1 => col2 pairs for the given SELECT statement</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last"><p>The result object with key-value pairs</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line289">line 289</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>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The SQL to run</p>
</td>
</tr>
<tr>
<td class="name"><code>...bindVars</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>The values to bind to the each question mark or named binding</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="selectId"><span class="type-signature"></span>selectId<span class="signature">(table, id)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Select the record with the given id</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
|
<span class="param-type"><code>undefined</code></span>
</td>
<td class="description last"><p>The result row or undefined</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line564">line 564</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>table</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the table from which to select</p>
</td>
</tr>
<tr>
<td class="name"><code>id</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The value of the id column</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="selectIndexed"><span class="type-signature">(async) </span>selectIndexed<span class="signature">(indexField, sql)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Return records all indexed by one of the column's values</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last"><p>The results indexed by indexField</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line356">line 356</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>indexField</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the field to index by</p>
</td>
</tr>
<tr>
<td class="name"><code>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The SQL to run</p>
</td>
</tr>
<tr>
<td class="name"><code>...bindVars</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>The values to bind to the each question mark or named binding</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="selectList"><span class="type-signature">(async) </span>selectList<span class="signature">(sql)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Return result array as col1 for the given SELECT statement</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Array</code></span>
</td>
<td class="description last"><p>The result list</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line309">line 309</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>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The SQL to run</p>
</td>
</tr>
<tr>
<td class="name"><code>...bindVars</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>The values to bind to the each question mark or named binding</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="selectOrCreate"><span class="type-signature"></span>selectOrCreate<span class="signature">(table, criteria, newValues)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Find a record or add a new one</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
|
<span class="param-type"><code>undefined</code></span>
</td>
<td class="description last"><p>The result row or undefined</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
<tr>
<td class="name"><code>insertId</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The id of the last inserted record</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line592">line 592</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>table</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the table from which to select</p>
</td>
</tr>
<tr>
<td class="name"><code>criteria</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>Criteria by which to find the row</p>
</td>
</tr>
<tr>
<td class="name"><code>newValues</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The values to use to insert if the record doesn't exist</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="selectOrCreateId"><span class="type-signature"></span>selectOrCreateId<span class="signature">(table, criteria, newValues)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Find a record's id or add a new one</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last"><p>The result row or new values</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
<tr>
<td class="name"><code>insertId</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The id of the last inserted record</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line649">line 649</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>table</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the table from which to select</p>
</td>
</tr>
<tr>
<td class="name"><code>criteria</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>Criteria by which to find the row</p>
</td>
</tr>
<tr>
<td class="name"><code>newValues</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The values to use to insert if the record doesn't exist</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="selectUuid"><span class="type-signature"></span>selectUuid<span class="signature">(table, uuid)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Select the record with the given UUID</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
|
<span class="param-type"><code>undefined</code></span>
</td>
<td class="description last"><p>The result row or undefined</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line577">line 577</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>table</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the table from which to select</p>
</td>
</tr>
<tr>
<td class="name"><code>uuid</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The value of the uuid column</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="selectValue"><span class="type-signature">(async) </span>selectValue<span class="signature">(sql)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Return first column value for the first result row for the given SELECT statement</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>results</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last"><p>The value returned in the first field of the first row</p></td>
</tr>
<tr>
<td class="name"><code>fields</code></td>
<td class="type">
<span class="param-type"><code>Array.<Object></code></span>
</td>
<td class="description last"><p>Info about the selected fields</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line396">line 396</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>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The SQL to run</p>
</td>
</tr>
<tr>
<td class="name"><code>...bindVars</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>The values to bind to the each question mark or named binding</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="startTransaction"><span class="type-signature"></span>startTransaction<span class="signature">()</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>run START TRANSACTION</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line831">line 831</a>
</li></ul></dd>
</dl>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="tpl"><span class="type-signature"></span>tpl<span class="signature">()</span><span class="type-signature"> → {Object}</span></h4>
<div class="description">
<p>Return an object with query methods to run on template literals
(backticked strings) where interpolated strings are automatically escaped</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>select</code></td>
<td class="type">
<span class="param-type"><code>function</code></span>
</td>
<td class="description last"><p>Same as Db#select()</p></td>
</tr>
<tr>
<td class="name"><code>selectFirst</code></td>
<td class="type">
<span class="param-type"><code>function</code></span>
</td>
<td class="description last"><p>Same as Db#selectFirst()</p></td>
</tr>
<tr>
<td class="name"><code>selectList</code></td>
<td class="type">
<span class="param-type"><code>function</code></span>
</td>
<td class="description last"><p>Same as Db#selectList()</p></td>
</tr>
<tr>
<td class="name"><code>selectHash</code></td>
<td class="type">
<span class="param-type"><code>function</code></span>
</td>
<td class="description last"><p>Same as Db#selectHash()</p></td>
</tr>
<tr>
<td class="name"><code>selectValue</code></td>
<td class="type">
<span class="param-type"><code>function</code></span>
</td>
<td class="description last"><p>Same as Db#selectValue()</p></td>
</tr>
<tr>
<td class="name"><code>insert</code></td>
<td class="type">
<span class="param-type"><code>function</code></span>
</td>
<td class="description last"><p>Same as Db#insert()</p></td>
</tr>
<tr>
<td class="name"><code>update</code></td>
<td class="type">
<span class="param-type"><code>function</code></span>
</td>
<td class="description last"><p>Same as Db#update()</p></td>
</tr>
<tr>
<td class="name"><code>delete</code></td>
<td class="type">
<span class="param-type"><code>function</code></span>
</td>
<td class="description last"><p>Same as Db#delete()</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line986">line 986</a>
</li></ul></dd>
</dl>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Object</code></span>
</dd>
</dl>
<div class="param-desc">
<p>Object with query methods</p>
</div>
</div>
<div class="section-examples">
<h5>Example</h5>
<pre class="prettyprint"><code>const db = Db.factory();
const { select, selectValue } = db.tpl();
const users = await select`SELECT * FROM users WHERE id IN(${userIds})`;
const count = await selectValue`SELECT COUNT(*) FROM users WHERE is_active = ${isActive}`;</code></pre>
</div>
</div>
<div class="section-method">
<h4 class="name" id="update"><span class="type-signature">(async) </span>update<span class="signature">(sql)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Run the given UPDATE statement</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>affectedRows</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The number of rows matching the WHERE criteria</p></td>
</tr>
<tr>
<td class="name"><code>changedRows</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The number of rows affected by the statement</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line471">line 471</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>sql</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
|
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>The SQL to run</p>
</td>
</tr>
<tr>
<td class="name"><code>...bindVars</code></td>
<td class="type">
<span class="param-type"><code>*</code></span>
</td>
<td class="description last">
<p>The values to bind to the each question mark or named binding</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
<div class="section-method">
<h4 class="name" id="updateTable"><span class="type-signature"></span>updateTable<span class="signature">(table, set, where)</span><span class="type-signature"> → {Promise.<Object>}</span></h4>
<div class="description">
<p>Build an UPDATE statement and run it</p>
</div>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>query</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last"><p>The final SQL that was executed</p></td>
</tr>
<tr>
<td class="name"><code>affectedRows</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The number of rows matching the WHERE criteria</p></td>
</tr>
<tr>
<td class="name"><code>changedRows</code></td>
<td class="type">
<span class="param-type"><code>Number</code></span>
</td>
<td class="description last"><p>The number of rows affected by the statement</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Db_Db.js.html">Db/Db.js</a>, <a href="Db_Db.js.html#line732">line 732</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>SqlBuilder#buildWheres</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>table</code></td>
<td class="type">
<span class="param-type"><code>String</code></span>
</td>
<td class="description last">
<p>The name of the table</p>
</td>
</tr>
<tr>
<td class="name"><code>set</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>An array of column-value pairs to update</p>
</td>
</tr>
<tr>
<td class="name"><code>where</code></td>
<td class="type">
<span class="param-type"><code>Object</code></span>
</td>
<td class="description last">
<p>Params to construct the WHERE clause - see SqlBuilder#buildWheres</p>
</td>
</tr>
</tbody>
</table>
<div class="section-returns">
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type:
</dt>
<dd>
<span class="param-type"><code>Promise.<Object></code></span>
</dd>
</dl>
</div>
</div>
</article>
</section>
</div>
<br class="clear">
<footer>
Generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Mon Sep 05 2022 18:14:46 GMT-0600 (Mountain Daylight Time) using the Minami theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>