Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@ Db.prototype.createQuery = function () {
return new Query(this);
};

/**
* Create a create query.
*
* @return {Query} The query instance.
*/
Db.prototype.create = function () {
var query = this.createQuery();
return query.create.apply(query, arguments);
};

/**
* Create a select query.
*
Expand Down
11 changes: 10 additions & 1 deletion lib/db/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,16 @@ Statement.prototype.buildStatement = function () {
if (state.from && state.from.length) {
statement.push('FROM');
statement.push(state.from.map(function (item) {
if (typeof item === 'string') {
if (typeof item === 'function') {
var child = new Statement(self.db);
child._state.paramIndex = self._state.paramIndex;
item(child);
return '(' + child.toString() + ')';
}
else if (item instanceof Statement) {
return '(' + item.toString() + ')';
}
else if (typeof item === 'string') {
return item;
}
else {
Expand Down
10 changes: 10 additions & 0 deletions test/db/statement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ COMMIT \n\
this.statement.select().from('(SELECT * FROM OUser)');
this.statement.buildStatement().should.equal('SELECT * FROM (SELECT * FROM OUser)');
});
it('should select from a subquery', function () {
this.statement.select().from((new Statement(this.db).select().from('OUser')));
this.statement.buildStatement().should.equal('SELECT * FROM (SELECT * FROM OUser)');
});
it('should select from a subquery, using a function', function () {
this.statement.select().from(function (s) {
s.select().from('OUser');
});
this.statement.buildStatement().should.equal('SELECT * FROM (SELECT * FROM OUser)');
});
});

describe('Statement::to()', function () {
Expand Down