Skip to content

Commit

Permalink
Merge pull request #11 from nicjansma/master
Browse files Browse the repository at this point in the history
Two changes: where() function values of 0, and query .as() function
  • Loading branch information
xavierlacot committed Nov 2, 2011
2 parents 8d4e4c9 + cdbcf58 commit 5052576
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions joli.js
Expand Up @@ -433,7 +433,8 @@ joli.query = function() {
select_columns: '*',
set: [],
values: [],
where: null
where: null,
as: null
};
};

Expand Down Expand Up @@ -479,6 +480,11 @@ joli.query.prototype = {
return this;
},

as: function(table) {
this.data.as = table;
return this;
},

getCount: function(rows) {
var result;

Expand Down Expand Up @@ -616,7 +622,9 @@ joli.query.prototype = {
var i;
var record;
var rowData;
var model = joli.models.get(this.data.from);

// use the model specified by as() first, then from()
var model = joli.models.get(this.data.as || this.data.from);

while (rows.isValidRow()) {
i = 0;
Expand Down Expand Up @@ -707,7 +715,7 @@ joli.query.prototype = {
var i = 0;

// replace question marks one at a time from the array
while (expression.indexOf('?') != -1 && value[i]) {
while (expression.indexOf('?') != -1 && value[i] !== undefined) {
expression = expression.replace(/\?/i, '"' + value[i] + '"');
i++;
}
Expand Down

0 comments on commit 5052576

Please sign in to comment.