2016-09-26 09:28:47 +00:00
|
|
|
|
|
|
|
var Stmt = require ('./stmt');
|
|
|
|
var Field = require ('./field');
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
/**
|
|
|
|
* The equivalent of a SQL select.
|
|
|
|
**/
|
2016-09-26 09:28:47 +00:00
|
|
|
module.exports = new Class
|
2015-01-23 13:09:30 +00:00
|
|
|
({
|
2016-09-26 09:28:47 +00:00
|
|
|
Extends: Stmt
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
,expr: []
|
|
|
|
|
|
|
|
,addField: function (fieldName)
|
|
|
|
{
|
2016-09-26 09:28:47 +00:00
|
|
|
this.expr.push (new Field ({name: fieldName}));
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,render: function (batch)
|
|
|
|
{
|
|
|
|
var sql = 'SELECT '
|
|
|
|
|
|
|
|
for (var i = 0; i < this.expr.length; i++)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
sql += ', ';
|
|
|
|
sql += this.expr[i].render(batch);
|
|
|
|
}
|
|
|
|
|
|
|
|
sql += ' FROM ' + this.renderTarget (batch);
|
|
|
|
|
|
|
|
if (this.where)
|
|
|
|
sql += ' WHERE ' + this.where.render (batch);
|
|
|
|
|
|
|
|
return sql;
|
|
|
|
}
|
|
|
|
});
|