2014-10-20 16:56:45 -04:00
|
|
|
<!DOCTYPE html>
|
2014-10-23 10:53:16 -04:00
|
|
|
|
2014-10-20 16:56:45 -04:00
|
|
|
<html lang="en">
|
|
|
|
<head>
|
2014-10-23 10:53:16 -04:00
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>DocStrap Source: driver.js</title>
|
2014-10-20 16:56:45 -04:00
|
|
|
|
2014-10-23 10:53:16 -04:00
|
|
|
<!--[if lt IE 9]>
|
|
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
|
|
<![endif]-->
|
|
|
|
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
|
2014-10-20 16:56:45 -04:00
|
|
|
|
2014-10-23 10:53:16 -04:00
|
|
|
<link type="text/css" rel="stylesheet" href="styles/site.cosmo.css">
|
2014-10-20 16:56:45 -04:00
|
|
|
|
2014-10-23 10:53:16 -04:00
|
|
|
</head>
|
2014-10-20 16:56:45 -04:00
|
|
|
|
2014-10-23 10:53:16 -04:00
|
|
|
<body>
|
|
|
|
<div class="container-fluid">
|
|
|
|
<div class="navbar navbar-fixed-top navbar-inverse">
|
|
|
|
<div class="navbar-inner">
|
|
|
|
<a class="brand" href="index.html">DocStrap</a>
|
|
|
|
<ul class="nav">
|
|
|
|
|
|
|
|
<li class="dropdown">
|
|
|
|
<a href="modules.list.html" class="dropdown-toggle" data-toggle="dropdown">Modules<b
|
|
|
|
class="caret"></b></a>
|
|
|
|
|
|
|
|
<ul class="dropdown-menu ">
|
|
|
|
|
|
|
|
<li>
|
|
|
|
<a href="module-adapter.html">adapter</a>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<li>
|
|
|
|
<a href="module-driver.html">driver</a>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<li>
|
|
|
|
<a href="module-helpers.html">helpers</a>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<li>
|
|
|
|
<a href="module-node-query.html">node-query</a>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<li>
|
|
|
|
<a href="module-query-builder.html">query-builder</a>
|
|
|
|
</li>
|
|
|
|
|
2014-10-27 10:35:44 -04:00
|
|
|
<li>
|
|
|
|
<a href="module-query-parser.html">query-parser</a>
|
|
|
|
</li>
|
|
|
|
|
2014-10-23 10:53:16 -04:00
|
|
|
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="row-fluid">
|
|
|
|
|
|
|
|
|
|
|
|
<div class="span12">
|
|
|
|
|
|
|
|
<div id="main">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h1 class="page-title">Source: driver.js</h1>
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<article>
|
|
|
|
<pre
|
|
|
|
class="sunlight-highlight-javascript linenums">'use strict';
|
2014-10-20 16:56:45 -04:00
|
|
|
|
|
|
|
var helpers = require('./helpers');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base Database Driver
|
|
|
|
*
|
2014-10-23 10:53:16 -04:00
|
|
|
* @module driver
|
2014-10-20 16:56:45 -04:00
|
|
|
*/
|
2014-10-23 10:53:16 -04:00
|
|
|
var d = {
|
2014-10-20 16:56:45 -04:00
|
|
|
identifierChar: '"',
|
|
|
|
tablePrefix: null,
|
2014-10-27 13:36:32 -04:00
|
|
|
hasTruncate: true,
|
2014-10-20 16:56:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Low level function for naive quoting of strings
|
|
|
|
|
|
|
|
* @param {String} str
|
|
|
|
* @return {String}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_quote: function(str) {
|
2014-10-23 10:53:16 -04:00
|
|
|
return (helpers.isString(str) && ! (str.startsWith(d.identifierChar) || str.endsWith(d.identifierChar)))
|
|
|
|
? d.identifierChar + str + d.identifierChar
|
2014-10-20 16:56:45 -04:00
|
|
|
: 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;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Quote database table name, and set prefix
|
|
|
|
*
|
|
|
|
* @param {String} table
|
|
|
|
* @return {String}
|
|
|
|
*/
|
|
|
|
quoteTable: function(table) {
|
|
|
|
// Quote after prefix
|
2014-10-23 10:53:16 -04:00
|
|
|
return d.quoteIdentifiers(table);
|
2014-10-20 16:56:45 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use the driver's escape character to quote identifiers
|
|
|
|
*
|
|
|
|
* @param {String|Array}
|
|
|
|
* @return {String|Array}
|
|
|
|
*/
|
|
|
|
quoteIdentifiers: function(str) {
|
|
|
|
var hiers, raw;
|
2014-10-23 11:59:42 -04:00
|
|
|
var pattern = new RegExp(d.identifierChar + '(' + '([a-zA-Z0-9_]+)' + '(\((.*?)\))' + ')' + d.identifierChar, 'ig');
|
2014-10-20 16:56:45 -04:00
|
|
|
|
|
|
|
// Recurse for arrays of identifiiers
|
|
|
|
if (Array.isArray(str))
|
|
|
|
{
|
2014-10-23 10:53:16 -04:00
|
|
|
return str.map(d.quoteIdentifiers);
|
2014-10-20 16:56:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handle commas
|
2014-10-23 15:49:17 -04:00
|
|
|
if (str.contains(','))
|
|
|
|
{
|
|
|
|
var parts = str.split(',').map(helpers.stringTrim);
|
|
|
|
str = parts.map(d.quoteIdentifiers).join(',');
|
|
|
|
}
|
2014-10-20 16:56:45 -04:00
|
|
|
|
|
|
|
// Split identifiers by period
|
2014-10-23 10:53:16 -04:00
|
|
|
hiers = str.split('.').map(d._quote);
|
2014-10-20 16:56:45 -04:00
|
|
|
raw = hiers.join('.');
|
|
|
|
|
2014-10-23 11:59:42 -04:00
|
|
|
// Fix functions
|
|
|
|
if (raw.contains('(') && raw.contains(')'))
|
|
|
|
{
|
|
|
|
var funcs = pattern.exec(raw);
|
|
|
|
|
|
|
|
// Unquote the function
|
|
|
|
raw = raw.replace(funcs[0], funcs[1]);
|
|
|
|
|
|
|
|
// Quote the identifiers inside of the parens
|
|
|
|
var inParens = funcs[3].substring(1, funcs[3].length -1);
|
|
|
|
raw = raw.replace(inParens, d.quoteIdentifiers(inParens));
|
|
|
|
}
|
2014-10-20 16:56:45 -04:00
|
|
|
|
|
|
|
return raw;
|
2014-10-27 13:36:32 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SQL to truncate the passed table
|
|
|
|
*
|
|
|
|
* @param {String} table
|
|
|
|
* @return {String} - sql
|
|
|
|
*/
|
|
|
|
truncate: function(table) {
|
|
|
|
var sql = (d.hasTruncate)
|
|
|
|
? 'TRUNCATE '
|
|
|
|
: 'DELETE FROM ';
|
|
|
|
|
|
|
|
sql += d.quoteTable(table);
|
|
|
|
|
|
|
|
return sql;
|
2014-10-30 09:48:55 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SQL to insert a group of rows
|
|
|
|
*
|
|
|
|
* @param {String} table - The table to insert to
|
|
|
|
* @param {Array} [data] - The array of object containing data to insert
|
|
|
|
* @return {String}
|
|
|
|
*/
|
|
|
|
insertBatch: function(table, data) {
|
|
|
|
|
|
|
|
// Get the data values to insert, so they can
|
|
|
|
// be parameterized
|
|
|
|
var vals = [];
|
|
|
|
data.forEach(function(obj) {
|
|
|
|
Object.keys(obj).forEach(function(key) {
|
|
|
|
vals.push(obj[key]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Get the field names from the keys of the first
|
|
|
|
// object inserted
|
|
|
|
var fields = Object.keys(data[0]);
|
|
|
|
table = d.quoteTable(table);
|
|
|
|
|
|
|
|
var sql = "INSERT INTO " + table + " ("
|
|
|
|
+ d.quoteIdentifiers(fields).join(",")
|
|
|
|
+ ") VALUES ";
|
|
|
|
|
|
|
|
// Create placeholder groups
|
|
|
|
var params = new Array(fields.length).fill('?');
|
|
|
|
var paramString = "(" + params.join(',') + ")";
|
|
|
|
var paramList = new Array(data.length).fill(paramString);
|
|
|
|
|
|
|
|
sql += paramList.join(',');
|
|
|
|
|
|
|
|
return {
|
|
|
|
sql: sql,
|
|
|
|
values: vals
|
|
|
|
};
|
2014-10-20 16:56:45 -04:00
|
|
|
}
|
2014-10-30 09:48:55 -04:00
|
|
|
|
2014-10-23 10:53:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = d;</pre>
|
|
|
|
</article>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="clearfix"></div>
|
|
|
|
<footer>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="copyright">
|
|
|
|
DocStrap Copyright © 2012-2014 The contributors to the JSDoc3 and DocStrap projects.
|
|
|
|
</span>
|
|
|
|
<br />
|
|
|
|
|
|
|
|
<span class="jsdoc-message">
|
|
|
|
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a>
|
2014-10-31 11:58:12 -04:00
|
|
|
on Fri Oct 31st 2014 using the <a
|
2014-10-23 10:53:16 -04:00
|
|
|
href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
|
|
|
|
</span>
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<br clear="both">
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<!--<script src="scripts/sunlight.js"></script>-->
|
|
|
|
<script src="scripts/docstrap.lib.js"></script>
|
|
|
|
<script src="scripts/bootstrap-dropdown.js"></script>
|
|
|
|
<script src="scripts/toc.js"></script>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
$( function () {
|
|
|
|
$( "[id*='$']" ).each( function () {
|
|
|
|
var $this = $( this );
|
|
|
|
|
|
|
|
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( "#toc" ).toc( {
|
|
|
|
anchorName : function ( i, heading, prefix ) {
|
|
|
|
return $( heading ).attr( "id" ) || ( prefix + i );
|
|
|
|
},
|
|
|
|
selectors : "h1,h2,h3,h4",
|
|
|
|
showAndHide : false,
|
|
|
|
scrollTo : "100px"
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
|
|
|
|
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
|
|
|
|
$( '.dropdown-toggle' ).dropdown();
|
|
|
|
// $( ".tutorial-section pre, .readme-section pre" ).addClass( "sunlight-highlight-javascript" ).addClass( "linenums" );
|
|
|
|
|
|
|
|
$( ".tutorial-section pre, .readme-section pre" ).each( function () {
|
|
|
|
var $this = $( this );
|
|
|
|
|
|
|
|
var example = $this.find( "code" );
|
|
|
|
exampleText = example.html();
|
|
|
|
var lang = /{@lang (.*?)}/.exec( exampleText );
|
|
|
|
if ( lang && lang[1] ) {
|
|
|
|
exampleText = exampleText.replace( lang[0], "" );
|
|
|
|
example.html( exampleText );
|
|
|
|
lang = lang[1];
|
|
|
|
} else {
|
|
|
|
lang = "javascript";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( lang ) {
|
|
|
|
|
|
|
|
$this
|
|
|
|
.addClass( "sunlight-highlight-" + lang )
|
|
|
|
.addClass( "linenums" )
|
|
|
|
.html( example.html() );
|
|
|
|
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
Sunlight.highlightAll( {
|
|
|
|
lineNumbers : true,
|
|
|
|
showMenu : true,
|
|
|
|
enableDoclinks : true
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--Navigation and Symbol Display-->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--Google Analytics-->
|
|
|
|
|
2014-10-20 16:56:45 -04:00
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|