-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
78 lines (70 loc) · 1.9 KB
/
index.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
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
var dbList = {
sqlServer:{
name: 'Microsoft SQL Server',
script: require('./db/sqlServer')
},
oracle:{
name: 'Oracle',
script: require('./db/oracle')
},
mysql:{
name: 'MySQL',
script: require('./db/mysql')
},
postgreSql:{
name: 'PostgreSQL',
script: require('./db/postgreSql')
},
db2:{
name: 'IBM DB2',
script: require('./db/db2')
},
mariadb:{
name: 'MariaDB',
script: require('./db/mariadb')
},
mongodb:{
name: 'MongoDB',
script: require('./db/mongodb')
},
sybase:{
name: 'SAP ASE / Sybase',
script: require('./db/sybase')
}
};
var executeQueries = function(type, host, port, user, password, db, queries, options, cb){
if(typeof options === 'function') cb = [options, options = cb][0];
if(Object.keys(dbList).indexOf(type) == -1) return cb('Unknown Database type');
if(!host || !db || !queries) return cb('Insufficient parameters');
if(typeof queries === 'string'){
var singleQuery = true;
queries = [queries];
}
dbList[type].script.executeQueries(host, port, user, password, db, queries, options, function(err, data){
if(err) return cb(err);
if(singleQuery) data = data[0];
if(data instanceof Error) return cb(data);
return cb(null, data);
});
};
var testConnection = function(type, host, port, user, password, db, options, cb){
if(typeof options === 'function') cb = [options, options = cb][0];
if(Object.keys(dbList).indexOf(type) == -1) return cb('Unknown Database type');
if(!host || !db) return cb('Insufficient parameters');
dbList[type].script.testConnection(host, port, user, password, db, options, function(err, data){
if(err) return cb(err);
return cb();
});
};
var getConnectionTypes = function (){
var types = [];
for (dbName in dbList){
types.push({key: dbName, name: dbList[dbName].name});
}
return types;
};
module.exports = {
executeQueries: executeQueries,
testConnection: testConnection,
getConnectionTypes: getConnectionTypes
};