node-query/docs/query-parser.js.html
2014-12-01 14:05:06 -05:00

268 lines
6.0 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>DocStrap Source: query-parser.js</title>
<!--[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">
<link type="text/css" rel="stylesheet" href="styles/site.cosmo.css">
</head>
<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>
<li>
<a href="module-query-parser.html">query-parser</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<div id="main">
<h1 class="page-title">Source: query-parser.js</h1>
<section>
<article>
<pre
class="sunlight-highlight-javascript linenums">'use strict';
var helpers = require('./helpers');
var matchPatterns = {
'function': /([a-zA-Z0-9_]+\((.*?)\))/i,
identifier: /([a-zA-Z0-9_\-]+\.?)+/ig,
operator: /\=|AND|&amp;&amp;?|~|\|\|?|\^|\/|>=?|&lt;=?|-|%|OR|\+|NOT|\!=?|&lt;>|XOR/i
};
// Full pattern for determining ordering of the pieces
matchPatterns.combined = new RegExp(matchPatterns['function'].source + "+|"
+ matchPatterns.identifier.source
+ '|(' + matchPatterns.operator.source + ')+', 'ig');
var filterMatches = function(array) {
var output = [];
// Return non-array matches
if (helpers.isScalar(array) || helpers.isNull(array) || helpers.isUndefined(array)) return output;
array.forEach(function(item) {
output.push(item);
});
return output;
};
// --------------------------------------------------------------------------
/**
* @constructor
* @param {Driver} - The driver object for the database in use
* @module query-parser
*/
var QueryParser = function(driver) {
// That 'new' keyword is annoying
if ( ! (this instanceof QueryParser)) return new QueryParser(driver);
/**
* Tokenize the sql into parts for additional processing
*
* @param {String} sql
* @return {Object}
*/
this.parseJoin = function(sql) {
var matches = {};
var output = {};
// Get clause components
matches['function'] = sql.match(matchPatterns['function']);
matches.identifiers = sql.match(matchPatterns.identifier);
matches.operators = sql.match(matchPatterns.operator);
// Get everything at once for ordering
matches.combined = sql.match(matchPatterns.combined);
// Flatten the matches to increase relevance
Object.keys(matches).forEach(function(key) {
output[key] = filterMatches(matches[key]);
});
return output;
};
/**
* Return the output of the parsing of the join condition
*
* @param {String} condition - The join condition to evalate
* @return {String} - The parsed/escaped join condition
*/
this.compileJoin = function(condition) {
var parts = this.parseJoin(condition);
var count = parts.identifiers.length;
var i;
// Quote the identifiers
parts.combined.forEach(function(part, i) {
if (parts.identifiers.indexOf(part) !== -1 &amp;&amp; ! helpers.isNumber(part))
{
parts.combined[i] = driver.quoteIdentifiers(part);
}
});
return parts.combined.join('');
};
};
module.exports = QueryParser;
</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>
on Mon Dec 1st 2014 using the <a
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-->
</body>
</html>