Update docs and version

This commit is contained in:
Timothy Warren 2014-10-28 16:47:30 -04:00
parent 711cc0c4f8
commit d1e1d64912
6 changed files with 23 additions and 61 deletions

View File

@ -100,22 +100,6 @@ var d = {
: str; : str;
}, },
/**
* Sets the table prefix on the passed string
*
* @param {String} str
* @return {String}
* @private
*/
_prefix: function(str) {
if (str.startsWith(d.prefix))
{
return str;
}
return d.prefix + str;
},
/** /**
* Set the limit clause * Set the limit clause
@ -135,32 +119,6 @@ var d = {
return sql; return sql;
}, },
/**
* Prefixes a table if it is not already prefixed
*
* @param {String} table
* @return {String}
*/
prefixTable: function(table) {
if (d.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] = d._prefix(idents[segments - 1]);
table = idents.join('.');
}
return table;
},
/** /**
* Quote database table name, and set prefix * Quote database table name, and set prefix
* *
@ -168,8 +126,6 @@ var d = {
* @return {String} * @return {String}
*/ */
quoteTable: function(table) { quoteTable: function(table) {
table = d.prefixTable(table);
// Quote after prefix // Quote after prefix
return d.quoteIdentifiers(table); return d.quoteIdentifiers(table);
}, },

View File

@ -138,6 +138,11 @@ types.forEach(function (t) {
* @return {Boolean} * @return {Boolean}
*/ */
h['is' + t] = function (o) { h['is' + t] = function (o) {
if (t.toLowerCase() === 'infinite')
{
t = 'infinity';
}
return h.type(o) === t.toLowerCase(); return h.type(o) === t.toLowerCase();
}; };
}); });

View File

@ -955,7 +955,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-861">line 861</a> <a href="query-builder.js.html#sunlight-1-line-862">line 862</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -1154,7 +1154,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-839">line 839</a> <a href="query-builder.js.html#sunlight-1-line-840">line 840</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -1546,7 +1546,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-850">line 850</a> <a href="query-builder.js.html#sunlight-1-line-851">line 851</a>
</li> </li>
</ul> </ul>
</dd> </dd>

View File

@ -104,7 +104,7 @@ nodeQuery.init = function (driverType, connObject, connLib) {
} }
}); });
return new qb(require(paths.driver), require(paths.adapter)(connObject)); return qb(require(paths.driver), require(paths.adapter)(connObject));
}; };

View File

@ -238,10 +238,6 @@ var QueryBuilder = function(driver, adapter) {
{ {
obj = args.$key; obj = args.$key;
} }
else
{
throw new Error("Invalid arguments passed");
}
Object.keys(obj).forEach(function(k) { Object.keys(obj).forEach(function(k) {
// If a single value for the return // If a single value for the return
@ -267,8 +263,6 @@ var QueryBuilder = function(driver, adapter) {
_p.mixedSet('whereValues', 'value', args.key, args.val); _p.mixedSet('whereValues', 'value', args.key, args.val);
}, },
where: function(key, val, conj) { where: function(key, val, conj) {
conj = conj || 'AND';
// Normalize key and value and insert into state.whereMap // Normalize key and value and insert into state.whereMap
_p.whereMixedSet(key, val); _p.whereMixedSet(key, val);
@ -300,6 +294,9 @@ var QueryBuilder = function(driver, adapter) {
} }
_p.appendMap(conj, item, 'where'); _p.appendMap(conj, item, 'where');
// Clear the where Map
state.whereMap = {};
}); });
}, },
having: function(/*key, val, conj*/) { having: function(/*key, val, conj*/) {
@ -326,6 +323,9 @@ var QueryBuilder = function(driver, adapter) {
string: item string: item
}); });
}); });
// Clear the where Map
state.whereMap = {};
}, },
whereIn: function(/*key, val, inClause, conj*/) { whereIn: function(/*key, val, inClause, conj*/) {
var args = getArgs('key:string, val:array, inClause:string, conj:string', arguments); var args = getArgs('key:string, val:array, inClause:string, conj:string', arguments);
@ -382,7 +382,7 @@ var QueryBuilder = function(driver, adapter) {
orderArray: [], orderArray: [],
groupArray: [], groupArray: [],
havingMap: [], havingMap: [],
whereMap: [], whereMap: {},
// Partials // Partials
selectString: '', selectString: '',
@ -759,7 +759,7 @@ var QueryBuilder = function(driver, adapter) {
* @return this * @return this
*/ */
this.groupStart = function() { this.groupStart = function() {
var conj = (state.queryMap.length &lt; 1) ? ' WHERE ' : ' '; var conj = (state.queryMap.length &lt; 1) ? ' WHERE ' : ' AND ';
_p.appendMap(conj, '(', 'groupStart'); _p.appendMap(conj, '(', 'groupStart');
return this; return this;
@ -895,13 +895,14 @@ var QueryBuilder = function(driver, adapter) {
* @param {Boolean} [reset=true] - Whether to reset the query builder so another query can be built * @param {Boolean} [reset=true] - Whether to reset the query builder so another query can be built
* @return String * @return String
*/ */
this.getCompiledSelect = function(table, reset) { this.getCompiledSelect = function(/*table, reset*/) {
if (table) var args = getArgs('[table]:string, [reset]:boolean', arguments);
if (args.table)
{ {
this.from(table); this.from(args.table);
} }
return _p.getCompile('get', table, reset); return _p.getCompile('get', args.table, args.reset);
}; };
/** /**

View File

@ -1,6 +1,6 @@
{ {
"name": "ci-node-query", "name": "ci-node-query",
"version": "0.0.3", "version": "0.0.4",
"description": "A query builder for node based on the one in CodeIgniter", "description": "A query builder for node based on the one in CodeIgniter",
"author": "Timothy J Warren <tim@timshomepage.net>", "author": "Timothy J Warren <tim@timshomepage.net>",
"engines": { "engines": {