-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathpretest.js
52 lines (49 loc) · 1.47 KB
/
pretest.js
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
var async = require('async');
var fs = require('fs');
var oracle = require('./')(settings);
var path = require('path');
var settings = require('./tests-settings');
var raw = fs.readFileSync(path.join(__dirname, 'test', 'test.sql'), 'utf8');
var statements = [];
var stmt = '';
// split test/test.sql file into statements, but strip any trailing ;s unless
// they are at the end of an indented line, wich indicates a substatement.
raw.split('\n').forEach(function(line) {
// test/test.sql uses "/" as dividers between related statements, so ignore
// them and any blank lines
if (/\//.test(line) || /^\s+$/.test(line)) {
return;
}
if (/^\S+.*;$/.test(line)) {
if (!/^end;$/i.test(line)) {
stmt += line.slice(0, -1);
} else {
stmt += line;
}
statements.push(stmt.trim());
stmt = '';
return;
}
stmt += line + '\n';
});
oracle.connect(settings, function(err, connection) {
if (err) {
console.error('Error connecting to %j:', settings, err);
throw err;
}
async.eachSeries(statements, runStmt, shutdown);
function runStmt(stmt, next) {
connection.execute(stmt, [], function(err) {
if (err) {
// ignore the errors, but mention them. The SQL script doesn't make
// consistent use of exception handling for things like dropping tables
// that don't exist.. (yet?)
console.error('%s => %s', stmt, err);
}
next();
});
}
function shutdown(err, res) {
connection.close();
}
});