Skip to content

Commit

Permalink
Adds support for Query.Text() to sql function calls (closes #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
dresende committed Jun 20, 2013
1 parent 9e35195 commit 995ed1f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ function SelectQuery(Dialect) {

if (Array.isArray(sql.from[i].select[j].c)) {
str += sql.from[i].select[j].c.map(function (el) {
if (typeof el.type == "function") {
switch (el.type()) {
case "text":
return Dialect.escapeVal(el.data);
default:
return el;
}
}
if (typeof el != "string") {
return el;
}
Expand Down
1 change: 1 addition & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var common = exports;
var Query = require('../');

common.Query = Query;
common.Text = Query.Text;

common.Select = function () {
var q = new (Query.Query)();
Expand Down
22 changes: 22 additions & 0 deletions test/integration/test-select-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var common = require('../common');
var assert = require('assert');

assert.equal(
common.Select().from('table1').fun('myfun', 'col1').build(),
"SELECT MYFUN(`col1`) FROM `table1`"
);

assert.equal(
common.Select().from('table1').fun('myfun', [ 'col1', 'col2']).build(),
"SELECT MYFUN(`col1`, `col2`) FROM `table1`"
);

assert.equal(
common.Select().from('table1').fun('myfun', [ 'col1', 'col2'], 'alias').build(),
"SELECT MYFUN(`col1`, `col2`) AS `alias` FROM `table1`"
);

assert.equal(
common.Select().from('table1').fun('myfun', [ 'col1', common.Text('col2') ], 'alias').build(),
"SELECT MYFUN(`col1`, 'col2') AS `alias` FROM `table1`"
);

0 comments on commit 995ed1f

Please sign in to comment.