node-query/docs/driver.js.html

179 lines
3.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: driver.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: driver.js</h1>
<section>
<article>
<pre class="prettyprint source"><code>/** @module driver */
"use strict";
var helpers = require('./helpers');
/**
* Base Database Driver
*
* @type {{identifierChar: string, quoteIdentifiers: quoteIdentifiers}}
*/
module.exports = {
identifierChar: '"',
tablePrefix: null,
/**
* Low level function for naive quoting of strings
* @param {String} str
* @return {String}
* @private
*/
_quote: function(str) {
return (helpers.isString(str) && ! (str.startsWith(this.identifierChar) || str.endsWith(this.identifierChar)))
? this.identifierChar + str + this.identifierChar
: str;
},
/**
* Sets the table prefix on the passed string
*
* @param {String} str
* @return {String}
* @private
*/
_prefix: function(str) {
if (str.startsWith(this.prefix))
{
return str;
}
return this.prefix + str;
},
/**
* Set the limit clause
* @param {String} sql
* @param {Number} limit
* @param {Number|null} offset
* @return {String}
*/
limit: function(sql, limit, offset) {
sql += " LIMIT " + limit;
if (helpers.isNumber(offset))
{
sql += " OFFSET " + offset;
}
return sql;
},
/**
* Prefixes a table if it is not already prefixed
*
* @param {String} table
* @return {String}
*/
prefixTable: function(table) {
if (this.tablePrefix)
{
// Split identifier by period, will split into:
// database.schema.table OR
// schema.table OR
// database.table OR
// table
var idents = table.split('.', table);
var segments = idents.length;
// Add the database prefix
idents[segments - 1] = this._prefix(idents[segments - 1]);
table = idents.join('.');
}
return table;
},
/**
* Quote database table name, and set prefix
*
* @param {String} table
* @return {String}
*/
quoteTable: function(table) {
table = this.prefixTable(table);
// Quote after prefix
return this.quoteIdentifiers(table);
},
/**
* Use the driver's escape character to quote identifiers
*
* @param {String|Array}
* @return {String|Array}
*/
quoteIdentifiers: function(str) {
var hiers, raw;
// Recurse for arrays of identifiiers
if (Array.isArray(str))
{
return str.map(this.quoteIdentifiers);
}
// Handle commas
str = helpers.splitTrim(',', str);
// Split identifiers by period
hiers = str.split('.').map(String.trim).map(this._quote);
raw = hiers.join('.');
// TODO: fix functions
return raw;
}
};</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-driver.html">driver</a></li><li><a href="module-helpers.html">helpers</a></li><li><a href="module-query-builder.html">query-builder</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.2</a> on Mon Oct 20 2014 16:34:02 GMT-0400 (EDT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>