-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
index.js
138 lines (113 loc) · 2.42 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
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
129
130
131
132
133
134
135
136
137
138
/**
* @module index
* @license MIT
* @version 2017/11/09
*/
'use strict';
// Import lib
const Proxy = require('./lib/proxy');
const engine = require('./lib/engine');
const debug = require('debug')('ADODB');
// Set debug color
debug.color = 6;
/**
* @class ADODB
*/
class ADODB {
/**
* @constructor
* @param {string} connection
* @param {boolean} [x64]
*/
constructor(connection, x64) {
this.connection = connection;
this.proxy = new Proxy(engine(x64));
}
/**
* @method execute
* @param {string} sql
* @param {string} [scalar]
* @returns {Promise}
*/
execute(sql, scalar) {
debug('cmd:', 'execute');
debug('sql:', sql);
const connection = this.connection;
const params = { connection, sql };
if (arguments.length > 1) {
debug('scalar:', scalar);
params.scalar = scalar;
}
return this.proxy.exec('execute', params);
}
/**
* @method transaction
* @param {string} sql
* @returns {Promise}
*/
transaction(sql) {
debug('cmd:', 'transaction');
debug('sql:', sql);
const connection = this.connection;
const params = { connection, sql };
return this.proxy.exec('transaction', params);
}
/**
* @method query
* @param {string} sql
* @returns {Promise}
*/
query(sql) {
debug('cmd:', 'query');
debug('sql:', sql);
const connection = this.connection;
return this.proxy.exec('query', { connection, sql });
}
/**
* @method schema
* @param {number} type
* @param {Array} [criteria]
* @param {string} [id]
* @returns {Promise}
*/
schema(type, criteria, id) {
debug('cmd:', 'schema');
debug('type:', type);
const length = arguments.length;
const connection = this.connection;
const params = { connection, type };
if (length > 1) {
debug('criteria:', criteria);
params.criteria = criteria;
}
if (length > 2) {
debug('id:', id);
params.id = id;
}
return this.proxy.exec('schema', params);
}
}
// Exports
module.exports = {
/**
* @property PATH
* @description Set ADODB PATH
*/
set PATH(adodb) {
Proxy.adodb = adodb;
},
/**
* @property PATH
* @description Get ADODB PATH
*/
get PATH() {
return Proxy.adodb;
},
/**
* @function open
* @param {string} connection
* @param {boolean} [x64]
* @returns {ADODB}
*/
open: (connection, x64) => new ADODB(connection, x64)
};