@miatechnet/node-odbc 2.4.10-multiresult.1 → 2.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/odbc.d.ts CHANGED
@@ -1,210 +1,210 @@
1
- declare namespace odbc {
2
-
3
- class ColumnDefinition {
4
- name: string;
5
- dataType: number;
6
- dataTypeName: string;
7
- columnSize: number;
8
- decimalDigits: number;
9
- nullable: boolean;
10
- }
11
-
12
- class Result<T> extends Array<T> {
13
- count: number;
14
- columns: Array<ColumnDefinition>;
15
- statement: string;
16
- parameters: Array<number|string>;
17
- return: number;
18
- }
19
-
20
- class OdbcError {
21
- message: string;
22
- code: number;
23
- state: string;
24
- }
25
-
26
- class NodeOdbcError extends Error {
27
- odbcErrors: Array<OdbcError>;
28
- }
29
-
30
- class Statement {
31
-
32
- ////////////////////////////////////////////////////////////////////////////
33
- // Callbacks ///////////////////////////////////////////////////////////
34
- ////////////////////////////////////////////////////////////////////////////
35
-
36
- prepare(sql: string, callback: (error: NodeOdbcError) => undefined): undefined;
37
-
38
- bind(parameters: Array<number|string>, callback: (error: NodeOdbcError) => undefined): undefined;
39
-
40
- execute<T>(callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
41
-
42
- close(callback: (error: NodeOdbcError) => undefined): undefined;
43
-
44
- ////////////////////////////////////////////////////////////////////////////
45
- // Promises ////////////////////////////////////////////////////////////
46
- ////////////////////////////////////////////////////////////////////////////
47
-
48
- prepare(sql: string): Promise<void>;
49
-
50
- bind(parameters: Array<number|string>): Promise<void>;
51
-
52
- execute<T>(): Promise<Result<T>>;
53
-
54
- close(): Promise<void>;
55
- }
56
-
57
- interface ConnectionParameters {
58
- connectionString: string;
59
- connectionTimeout?: number;
60
- loginTimeout?: number;
61
- }
62
- interface PoolParameters {
63
- connectionString: string;
64
- connectionTimeout?: number;
65
- loginTimeout?: number;
66
- initialSize?: number;
67
- incrementSize?: number;
68
- maxSize?: number;
69
- reuseConnections?: boolean;
70
- shrink?: boolean;
71
- }
72
-
73
- interface QueryOptions {
74
- cursor?: boolean|string;
75
- fetchSize?: number;
76
- timeout?: number;
77
- initialBufferSize?: number;
78
- }
79
-
80
- interface CursorQueryOptions extends QueryOptions {
81
- cursor: boolean|string
82
- }
83
-
84
- class Connection {
85
-
86
- ////////////////////////////////////////////////////////////////////////////
87
- // Callbacks ///////////////////////////////////////////////////////////
88
- ////////////////////////////////////////////////////////////////////////////
89
- query<T>(sql: string, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
90
- query<T>(sql: string, parameters: Array<number|string>, callback: (error: NodeOdbcError, result: Result<T> | Cursor) => undefined): undefined;
91
- query<T, O extends QueryOptions>(sql: string, options: O, callback: (error: NodeOdbcError, result: O extends CursorQueryOptions ? Cursor : Result<T>) => undefined): undefined;
92
- query<T, O extends QueryOptions>(sql: string, parameters: Array<number|string>, options: O, callback: (error: NodeOdbcError, result: O extends CursorQueryOptions ? Cursor : Result<T>) => undefined): undefined;
93
-
94
- callProcedure<T>(catalog: string|null, schema: string|null, name: string, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
95
- callProcedure<T>(catalog: string|null, schema: string|null, name: string, parameters: Array<number|string>, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
96
-
97
- createStatement(callback: (error: NodeOdbcError, statement: Statement) => undefined): undefined;
98
-
99
- primaryKeys<T>(catalog: string|null, schema: string|null, table: string|null, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
100
-
101
- foreignKeys<T>(pkCatalog: string|null, pkSchema: string|null, pkTable: string|null, fkCatalog: string|null, fkSchema: string|null, fkTable: string|null, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
102
-
103
- tables<T>(catalog: string|null, schema: string|null, table: string|null, type: string|null, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
104
-
105
- columns<T>(catalog: string|null, schema: string|null, table: string|null, column: string|null, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
106
-
107
- setIsolationLevel(level: number, callback: (error: NodeOdbcError) => undefined): undefined;
108
-
109
- beginTransaction(callback: (error: NodeOdbcError) => undefined): undefined;
110
-
111
- commit(callback: (error: NodeOdbcError) => undefined): undefined;
112
-
113
- rollback(callback: (error: NodeOdbcError) => undefined): undefined;
114
-
115
- close(callback: (error: NodeOdbcError) => undefined): undefined;
116
-
117
- ////////////////////////////////////////////////////////////////////////////
118
- // Promises ////////////////////////////////////////////////////////////
119
- ////////////////////////////////////////////////////////////////////////////
120
- query<T>(sql: string): Promise<Result<T>>;
121
- query<T>(sql: string, parameters: Array<number|string>): Promise<Result<T>>;
122
- query<T, O extends QueryOptions>(sql: string, options: O): O extends CursorQueryOptions ? Promise<Cursor> : Promise<Result<T>>;
123
- query<T, O extends QueryOptions>(sql: string, parameters: Array<number|string>, options: O): O extends CursorQueryOptions ? Promise<Cursor> : Promise<Result<T>>;
124
-
125
- callProcedure<T>(catalog: string|null, schema: string|null, name: string, parameters?: Array<number|string>): Promise<Result<T>>;
126
-
127
- createStatement(): Promise<Statement>;
128
-
129
- primaryKeys<T>(catalog: string|null, schema: string|null, table: string|null): Promise<Result<T>>;
130
-
131
- foreignKeys<T>(pkCatalog: string|null, pkSchema: string|null, pkTable: string|null, fkCatalog: string|null, fkSchema: string|null, fkTable: string|null): Promise<Result<T>>;
132
-
133
- tables<T>(catalog: string|null, schema: string|null, table: string|null, type: string|null): Promise<Result<T>>;
134
-
135
- columns<T>(catalog: string|null, schema: string|null, table: string|null, column: string|null): Promise<Result<T>>;
136
-
137
- setIsolationLevel(level: number): Promise<void>;
138
-
139
- beginTransaction(): Promise<void>;
140
-
141
- commit(): Promise<void>;
142
-
143
- rollback(): Promise<void>;
144
-
145
- close(): Promise<void>;
146
- }
147
-
148
- class Pool {
149
-
150
- ////////////////////////////////////////////////////////////////////////////
151
- // Callbacks ///////////////////////////////////////////////////////////
152
- ////////////////////////////////////////////////////////////////////////////
153
- connect(callback: (error: NodeOdbcError, connection: Connection) => undefined): undefined;
154
-
155
- query<T>(sql: string, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
156
- query<T>(sql: string, parameters: Array<number|string>, callback: (error: NodeOdbcError, result: Result<T> | Cursor) => undefined): undefined;
157
- query<T, O extends QueryOptions>(sql: string, options: O, callback: (error: NodeOdbcError, result: O extends CursorQueryOptions ? Cursor : Result<T>) => undefined): undefined;
158
- query<T, O extends QueryOptions>(sql: string, parameters: Array<number|string>, options: O, callback: (error: NodeOdbcError, result: O extends CursorQueryOptions ? Cursor : Result<T>) => undefined): undefined;
159
-
160
- close(callback: (error: NodeOdbcError) => undefined): undefined;
161
-
162
-
163
- ////////////////////////////////////////////////////////////////////////////
164
- // Promises ////////////////////////////////////////////////////////////
165
- ////////////////////////////////////////////////////////////////////////////
166
- connect(): Promise<Connection>;
167
-
168
- query<T>(sql: string): Promise<Result<T>>;
169
- query<T>(sql: string, parameters: Array<number|string>): Promise<Result<T>>;
170
- query<T, O extends QueryOptions>(sql: string, options: O): O extends CursorQueryOptions ? Promise<Cursor> : Promise<Result<T>>;
171
- query<T, O extends QueryOptions>(sql: string, parameters: Array<number|string>, options: O): O extends CursorQueryOptions ? Promise<Cursor> : Promise<Result<T>>;
172
-
173
- close(): Promise<void>;
174
- }
175
-
176
- class Cursor {
177
- noData: boolean
178
-
179
- ////////////////////////////////////////////////////////////////////////////
180
- // Promises ////////////////////////////////////////////////////////////
181
- ////////////////////////////////////////////////////////////////////////////
182
-
183
- fetch<T>(): Promise<Result<T>>
184
-
185
- close(): Promise<void>
186
-
187
- ////////////////////////////////////////////////////////////////////////////
188
- // Callbacks ///////////////////////////////////////////////////////////
189
- ////////////////////////////////////////////////////////////////////////////
190
-
191
- fetch<T>(callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined
192
-
193
- close(callback: (error: NodeOdbcError) => undefined): undefined
194
- }
195
-
196
- function connect(connectionString: string, callback: (error: NodeOdbcError, connection: Connection) => undefined): undefined;
197
- function connect(connectionObject: ConnectionParameters, callback: (error: NodeOdbcError, connection: Connection) => undefined): undefined;
198
-
199
- function connect(connectionString: string): Promise<Connection>;
200
- function connect(connectionObject: ConnectionParameters): Promise<Connection>;
201
-
202
-
203
- function pool(connectionString: string, callback: (error: NodeOdbcError, pool: Pool) => undefined): undefined;
204
- function pool(connectionObject: PoolParameters, callback: (error: NodeOdbcError, pool: Pool) => undefined): undefined;
205
-
206
- function pool(connectionString: string): Promise<Pool>;
207
- function pool(connectionObject: PoolParameters): Promise<Pool>;
208
- }
209
-
210
- export = odbc;
1
+ declare namespace odbc {
2
+
3
+ class ColumnDefinition {
4
+ name: string;
5
+ dataType: number;
6
+ dataTypeName: string;
7
+ columnSize: number;
8
+ decimalDigits: number;
9
+ nullable: boolean;
10
+ }
11
+
12
+ class Result<T> extends Array<T> {
13
+ count: number;
14
+ columns: Array<ColumnDefinition>;
15
+ statement: string;
16
+ parameters: Array<number|string>;
17
+ return: number;
18
+ }
19
+
20
+ class OdbcError {
21
+ message: string;
22
+ code: number;
23
+ state: string;
24
+ }
25
+
26
+ class NodeOdbcError extends Error {
27
+ odbcErrors: Array<OdbcError>;
28
+ }
29
+
30
+ class Statement {
31
+
32
+ ////////////////////////////////////////////////////////////////////////////
33
+ // Callbacks ///////////////////////////////////////////////////////////
34
+ ////////////////////////////////////////////////////////////////////////////
35
+
36
+ prepare(sql: string, callback: (error: NodeOdbcError) => undefined): undefined;
37
+
38
+ bind(parameters: Array<number|string>, callback: (error: NodeOdbcError) => undefined): undefined;
39
+
40
+ execute<T>(callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
41
+
42
+ close(callback: (error: NodeOdbcError) => undefined): undefined;
43
+
44
+ ////////////////////////////////////////////////////////////////////////////
45
+ // Promises ////////////////////////////////////////////////////////////
46
+ ////////////////////////////////////////////////////////////////////////////
47
+
48
+ prepare(sql: string): Promise<void>;
49
+
50
+ bind(parameters: Array<number|string>): Promise<void>;
51
+
52
+ execute<T>(): Promise<Result<T>>;
53
+
54
+ close(): Promise<void>;
55
+ }
56
+
57
+ interface ConnectionParameters {
58
+ connectionString: string;
59
+ connectionTimeout?: number;
60
+ loginTimeout?: number;
61
+ }
62
+ interface PoolParameters {
63
+ connectionString: string;
64
+ connectionTimeout?: number;
65
+ loginTimeout?: number;
66
+ initialSize?: number;
67
+ incrementSize?: number;
68
+ maxSize?: number;
69
+ reuseConnections?: boolean;
70
+ shrink?: boolean;
71
+ }
72
+
73
+ interface QueryOptions {
74
+ cursor?: boolean|string;
75
+ fetchSize?: number;
76
+ timeout?: number;
77
+ initialBufferSize?: number;
78
+ }
79
+
80
+ interface CursorQueryOptions extends QueryOptions {
81
+ cursor: boolean|string
82
+ }
83
+
84
+ class Connection {
85
+
86
+ ////////////////////////////////////////////////////////////////////////////
87
+ // Callbacks ///////////////////////////////////////////////////////////
88
+ ////////////////////////////////////////////////////////////////////////////
89
+ query<T>(sql: string, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
90
+ query<T>(sql: string, parameters: Array<number|string>, callback: (error: NodeOdbcError, result: Result<T> | Cursor) => undefined): undefined;
91
+ query<T, O extends QueryOptions>(sql: string, options: O, callback: (error: NodeOdbcError, result: O extends CursorQueryOptions ? Cursor : Result<T>) => undefined): undefined;
92
+ query<T, O extends QueryOptions>(sql: string, parameters: Array<number|string>, options: O, callback: (error: NodeOdbcError, result: O extends CursorQueryOptions ? Cursor : Result<T>) => undefined): undefined;
93
+
94
+ callProcedure<T>(catalog: string|null, schema: string|null, name: string, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
95
+ callProcedure<T>(catalog: string|null, schema: string|null, name: string, parameters: Array<number|string>, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
96
+
97
+ createStatement(callback: (error: NodeOdbcError, statement: Statement) => undefined): undefined;
98
+
99
+ primaryKeys<T>(catalog: string|null, schema: string|null, table: string|null, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
100
+
101
+ foreignKeys<T>(pkCatalog: string|null, pkSchema: string|null, pkTable: string|null, fkCatalog: string|null, fkSchema: string|null, fkTable: string|null, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
102
+
103
+ tables<T>(catalog: string|null, schema: string|null, table: string|null, type: string|null, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
104
+
105
+ columns<T>(catalog: string|null, schema: string|null, table: string|null, column: string|null, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
106
+
107
+ setIsolationLevel(level: number, callback: (error: NodeOdbcError) => undefined): undefined;
108
+
109
+ beginTransaction(callback: (error: NodeOdbcError) => undefined): undefined;
110
+
111
+ commit(callback: (error: NodeOdbcError) => undefined): undefined;
112
+
113
+ rollback(callback: (error: NodeOdbcError) => undefined): undefined;
114
+
115
+ close(callback: (error: NodeOdbcError) => undefined): undefined;
116
+
117
+ ////////////////////////////////////////////////////////////////////////////
118
+ // Promises ////////////////////////////////////////////////////////////
119
+ ////////////////////////////////////////////////////////////////////////////
120
+ query<T>(sql: string): Promise<Result<T>>;
121
+ query<T>(sql: string, parameters: Array<number|string>): Promise<Result<T>>;
122
+ query<T, O extends QueryOptions>(sql: string, options: O): O extends CursorQueryOptions ? Promise<Cursor> : Promise<Result<T>>;
123
+ query<T, O extends QueryOptions>(sql: string, parameters: Array<number|string>, options: O): O extends CursorQueryOptions ? Promise<Cursor> : Promise<Result<T>>;
124
+
125
+ callProcedure<T>(catalog: string|null, schema: string|null, name: string, parameters?: Array<number|string>): Promise<Result<T>>;
126
+
127
+ createStatement(): Promise<Statement>;
128
+
129
+ primaryKeys<T>(catalog: string|null, schema: string|null, table: string|null): Promise<Result<T>>;
130
+
131
+ foreignKeys<T>(pkCatalog: string|null, pkSchema: string|null, pkTable: string|null, fkCatalog: string|null, fkSchema: string|null, fkTable: string|null): Promise<Result<T>>;
132
+
133
+ tables<T>(catalog: string|null, schema: string|null, table: string|null, type: string|null): Promise<Result<T>>;
134
+
135
+ columns<T>(catalog: string|null, schema: string|null, table: string|null, column: string|null): Promise<Result<T>>;
136
+
137
+ setIsolationLevel(level: number): Promise<void>;
138
+
139
+ beginTransaction(): Promise<void>;
140
+
141
+ commit(): Promise<void>;
142
+
143
+ rollback(): Promise<void>;
144
+
145
+ close(): Promise<void>;
146
+ }
147
+
148
+ class Pool {
149
+
150
+ ////////////////////////////////////////////////////////////////////////////
151
+ // Callbacks ///////////////////////////////////////////////////////////
152
+ ////////////////////////////////////////////////////////////////////////////
153
+ connect(callback: (error: NodeOdbcError, connection: Connection) => undefined): undefined;
154
+
155
+ query<T>(sql: string, callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined;
156
+ query<T>(sql: string, parameters: Array<number|string>, callback: (error: NodeOdbcError, result: Result<T> | Cursor) => undefined): undefined;
157
+ query<T, O extends QueryOptions>(sql: string, options: O, callback: (error: NodeOdbcError, result: O extends CursorQueryOptions ? Cursor : Result<T>) => undefined): undefined;
158
+ query<T, O extends QueryOptions>(sql: string, parameters: Array<number|string>, options: O, callback: (error: NodeOdbcError, result: O extends CursorQueryOptions ? Cursor : Result<T>) => undefined): undefined;
159
+
160
+ close(callback: (error: NodeOdbcError) => undefined): undefined;
161
+
162
+
163
+ ////////////////////////////////////////////////////////////////////////////
164
+ // Promises ////////////////////////////////////////////////////////////
165
+ ////////////////////////////////////////////////////////////////////////////
166
+ connect(): Promise<Connection>;
167
+
168
+ query<T>(sql: string): Promise<Result<T>>;
169
+ query<T>(sql: string, parameters: Array<number|string>): Promise<Result<T>>;
170
+ query<T, O extends QueryOptions>(sql: string, options: O): O extends CursorQueryOptions ? Promise<Cursor> : Promise<Result<T>>;
171
+ query<T, O extends QueryOptions>(sql: string, parameters: Array<number|string>, options: O): O extends CursorQueryOptions ? Promise<Cursor> : Promise<Result<T>>;
172
+
173
+ close(): Promise<void>;
174
+ }
175
+
176
+ class Cursor {
177
+ noData: boolean
178
+
179
+ ////////////////////////////////////////////////////////////////////////////
180
+ // Promises ////////////////////////////////////////////////////////////
181
+ ////////////////////////////////////////////////////////////////////////////
182
+
183
+ fetch<T>(): Promise<Result<T>>
184
+
185
+ close(): Promise<void>
186
+
187
+ ////////////////////////////////////////////////////////////////////////////
188
+ // Callbacks ///////////////////////////////////////////////////////////
189
+ ////////////////////////////////////////////////////////////////////////////
190
+
191
+ fetch<T>(callback: (error: NodeOdbcError, result: Result<T>) => undefined): undefined
192
+
193
+ close(callback: (error: NodeOdbcError) => undefined): undefined
194
+ }
195
+
196
+ function connect(connectionString: string, callback: (error: NodeOdbcError, connection: Connection) => undefined): undefined;
197
+ function connect(connectionObject: ConnectionParameters, callback: (error: NodeOdbcError, connection: Connection) => undefined): undefined;
198
+
199
+ function connect(connectionString: string): Promise<Connection>;
200
+ function connect(connectionObject: ConnectionParameters): Promise<Connection>;
201
+
202
+
203
+ function pool(connectionString: string, callback: (error: NodeOdbcError, pool: Pool) => undefined): undefined;
204
+ function pool(connectionObject: PoolParameters, callback: (error: NodeOdbcError, pool: Pool) => undefined): undefined;
205
+
206
+ function pool(connectionString: string): Promise<Pool>;
207
+ function pool(connectionObject: PoolParameters): Promise<Pool>;
208
+ }
209
+
210
+ export = odbc;
package/lib/odbc.js CHANGED
@@ -1,56 +1,56 @@
1
- const binary = require('@mapbox/node-pre-gyp');
2
- const path = require('path');
3
-
4
- const bindingPath = binary.find(path.resolve(path.join(__dirname, '../package.json')));
5
-
6
- const nativeOdbc = require(bindingPath);
7
-
8
- const { Connection } = require('./Connection');
9
- const { Pool } = require('./Pool');
10
-
11
- function connect(connectionString, callback) {
12
- if (typeof callback !== 'function') {
13
- return new Promise((resolve, reject) => {
14
- nativeOdbc.connect(connectionString, (error, odbcConnection) => {
15
- if (error) {
16
- reject(error);
17
- } else {
18
- const connection = new Connection(odbcConnection);
19
- resolve(connection);
20
- }
21
- });
22
- });
23
- }
24
-
25
- return nativeOdbc.connect(connectionString, (error, odbcConnection) => {
26
- if (!error) {
27
- return callback(error, new Connection(odbcConnection));
28
- }
29
- return callback(error, null);
30
- });
31
- }
32
-
33
- function pool(options, callback) {
34
- const poolObj = new Pool(options);
35
-
36
- if (typeof callback !== 'function') {
37
- return new Promise(async (resolve, reject) => {
38
- try {
39
- await poolObj.init();
40
- resolve(poolObj);
41
- } catch(e) {
42
- reject(e);
43
- }
44
- });
45
- }
46
-
47
- return poolObj.init((error) => {
48
- callback(error, poolObj);
49
- });
50
- }
51
-
52
- module.exports = {
53
- pool,
54
- connect,
55
- ...nativeOdbc.odbcConstants,
56
- };
1
+ const binary = require('@mapbox/node-pre-gyp');
2
+ const path = require('path');
3
+
4
+ const bindingPath = binary.find(path.resolve(path.join(__dirname, '../package.json')));
5
+
6
+ const nativeOdbc = require(bindingPath);
7
+
8
+ const { Connection } = require('./Connection');
9
+ const { Pool } = require('./Pool');
10
+
11
+ function connect(connectionString, callback) {
12
+ if (typeof callback !== 'function') {
13
+ return new Promise((resolve, reject) => {
14
+ nativeOdbc.connect(connectionString, (error, odbcConnection) => {
15
+ if (error) {
16
+ reject(error);
17
+ } else {
18
+ const connection = new Connection(odbcConnection);
19
+ resolve(connection);
20
+ }
21
+ });
22
+ });
23
+ }
24
+
25
+ return nativeOdbc.connect(connectionString, (error, odbcConnection) => {
26
+ if (!error) {
27
+ return callback(error, new Connection(odbcConnection));
28
+ }
29
+ return callback(error, null);
30
+ });
31
+ }
32
+
33
+ function pool(options, callback) {
34
+ const poolObj = new Pool(options);
35
+
36
+ if (typeof callback !== 'function') {
37
+ return new Promise(async (resolve, reject) => {
38
+ try {
39
+ await poolObj.init();
40
+ resolve(poolObj);
41
+ } catch(e) {
42
+ reject(e);
43
+ }
44
+ });
45
+ }
46
+
47
+ return poolObj.init((error) => {
48
+ callback(error, poolObj);
49
+ });
50
+ }
51
+
52
+ module.exports = {
53
+ pool,
54
+ connect,
55
+ ...nativeOdbc.odbcConstants,
56
+ };