forked from brianc/node-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupport.js
More file actions
102 lines (81 loc) · 2.7 KB
/
support.js
File metadata and controls
102 lines (81 loc) · 2.7 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* global test */
'use strict';
var assert = require('assert');
var Table = require(__dirname + '/../../lib/table');
// specify dialect classes
var dialects = {
pg : require('../../lib/dialect/postgres'),
sqlite: require('../../lib/dialect/sqlite'),
mysql : require('../../lib/dialect/mysql')
};
module.exports = {
test: function(expected) {
// for each dialect
Object.keys(dialects).forEach(function(dialect) {
if(expected[dialect]) {
var DialectClass = dialects[dialect];
var title = dialect+': '+(expected.title || expected[dialect].text || expected[dialect]);
test(title, function() {
// check if this query is expected to throw
if(expected[dialect].throws) {
assert.throws(function() {
new DialectClass().getQuery(expected.query);
});
} else {
// build query for dialect
var compiledQuery = new DialectClass().getQuery(expected.query);
// test result is correct
var expectedText = expected[dialect].text || expected[dialect];
if(compiledQuery.text != expectedText) {
console.log();
console.log('actual ', compiledQuery.text);
console.log('expected', expectedText);
console.log();
}
assert.equal(compiledQuery.text, expectedText,'query result');
// if params are specified then test these are correct
var expectedParams = expected[dialect].params || expected.params;
if(expectedParams) {
assert.equal(expectedParams.length, compiledQuery.values.length, 'params length');
for(var i = 0; i < expectedParams.length; i++) {
assert.equal(expectedParams[i], compiledQuery.values[i], 'param '+(i+1));
}
}
}
});
} // if
}); // forEach
},
defineUserTable: function () {
return Table.define({
name: 'user',
quote: true,
columns: ['id','name']
});
},
definePostTable: function () {
return Table.define({
name: 'post',
columns: ['id', 'userId', 'content']
});
},
defineCommentTable: function () {
return Table.define({
name: 'comment',
columns: ['postId', 'text']
});
},
defineCustomerTable: function () {
return Table.define({
name: 'customer',
columns: ['id', 'name', 'age', 'income']
});
},
// This table contains column names that correspond to popularly used variables in formulas.
defineVariableTable: function() {
return Table.define({
name: 'variable',
columns: ['a', 'b', 'c', 'd', 't', 'u', 'v', 'x', 'y', 'z']
});
}
};