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
128 lines (111 loc) · 3.75 KB
/
support.js
File metadata and controls
128 lines (111 loc) · 3.75 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'use strict';
var assert = require('assert');
var Table = require('../../lib/table');
// specify dialect classes
var dialects = {
pg : require('../../lib/dialect/postgres'),
sqlite : require('../../lib/dialect/sqlite'),
mysql : require('../../lib/dialect/mysql'),
mssql : require('../../lib/dialect/mssql'),
oracle : require('../../lib/dialect/oracle')
};
module.exports = {
test: function(expected) {
// for each dialect
Object.keys(dialects).forEach(function(dialect) {
var expectedObject = expected[dialect];
if (undefined !== expectedObject) {
var DialectClass = dialects[dialect];
var title = dialect + ': ' + (expected.title || expectedObject.text || expectedObject);
test(title, function() {
// check if this query is expected to throw
if (expectedObject.throws) {
assert.throws(function() {
new DialectClass(expectedObject.config).getQuery(expected.query);
});
} else {
// build query for dialect
var compiledQuery = new DialectClass(expectedObject.config).getQuery(expected.query);
// test result is correct
var expectedText = expectedObject.text || expectedObject;
assert.equal(compiledQuery.text, expectedText);
// if params are specified then test these are correct
var expectedParams = expectedObject.params || expected.params;
if (undefined !== expectedParams) {
assert.equal(expectedParams.length, compiledQuery.values.length, 'params length');
for (var i = 0; i < expectedParams.length; i++) {
assert.deepEqual(expectedParams[i], compiledQuery.values[i], 'param ' + (i + 1));
}
}
}
if (undefined !== expectedObject.string) {
// test the toString
if (expectedObject.throws) {
assert.throws(function() {
new DialectClass(expectedObject.config).getString(expected.query);
});
} else {
var compiledString = new DialectClass(expectedObject.config).getString(expected.query);
// test result is correct
assert.equal(compiledString, expectedObject.string);
}
}
});
} // 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', 'tags']
});
},
defineCommentTable: function() {
return Table.define({
name: 'comment',
columns: ['postId', 'text']
});
},
defineCustomerTable: function() {
return Table.define({
name: 'customer',
columns: ['id', 'name', 'age', 'income', 'metadata']
});
},
// This table defines the customer attributes as a composite field
defineCustomerCompositeTable: function() {
return Table.define({
name: 'customer',
columns: {
id: {},
info: {subfields: ['name', 'age', 'salary']}
}
});
},
defineCustomerAliasTable: function() {
return Table.define({
name: 'customer',
columns: {
id: {property: 'id_alias'},
name: {property: 'name_alias'},
age: {property: 'age_alias'},
income: {property: 'income_alias'},
metadata: {property: 'metadata_alias'}
}
});
},
// 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']
});
}
};