forked from brianc/node-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolumn-tests.js
More file actions
33 lines (27 loc) · 1.05 KB
/
column-tests.js
File metadata and controls
33 lines (27 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var assert = require('assert');
var sql = require(__dirname + '/../lib');
describe('column', function() {
var table = sql.define({
name: 'user',
columns: ['id', 'created']
});
it('can be accessed by property and array', function() {
assert.equal(table.created, table.columns[1], 'should be able to access created both by array and property');
});
describe('toQuery()', function() {
it('works', function() {
assert.equal(table.id.toQuery().text, '"user"."id"');
});
it('respects AS rename', function() {
assert.equal(table.id.as('userId').toQuery().text, '"user"."id" AS "userId"');
});
it('respects count and distinct', function() {
assert.equal(table.id.count().distinct().as("userIdCount").toQuery().text, 'COUNT(DISTINCT("user"."id")) AS "userIdCount"');
});
describe('in subquery with min', function() {
var subquery = table.subQuery('subTable').select(table.id.min().as('subId'));
var col = subquery.subId.toQuery().text;
assert.equal(col, '"subTable"."subId"');
});
});
});