monetdb 1.3.4 → 2.0.1

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.
Files changed (55) hide show
  1. package/.github/workflows/Linux.yml +3 -3
  2. package/.github/workflows/docs.yml +79 -0
  3. package/.github/workflows/macos.yml +3 -3
  4. package/.github/workflows/monetdb-versions.yml +43 -0
  5. package/README.md +44 -514
  6. package/docs/components/alert.tsx +10 -0
  7. package/docs/components/info.tsx +6 -0
  8. package/docs/next.config.js +24 -0
  9. package/docs/package-lock.json +5069 -0
  10. package/docs/package.json +22 -0
  11. package/docs/pages/_app.js +9 -0
  12. package/docs/pages/_meta.json +18 -0
  13. package/docs/pages/apis/_meta.json +4 -0
  14. package/docs/pages/apis/connection.mdx +60 -0
  15. package/docs/pages/apis/result.mdx +39 -0
  16. package/docs/pages/filetransfer.mdx +43 -0
  17. package/docs/pages/index.mdx +27 -0
  18. package/docs/pages/prepstmt.mdx +13 -0
  19. package/docs/pages/result.mdx +41 -0
  20. package/docs/theme.config.js +35 -0
  21. package/docs/v1/README.md +532 -0
  22. package/package.json +16 -20
  23. package/src/PrepareStatement.ts +37 -0
  24. package/src/connection.ts +125 -0
  25. package/src/defaults.ts +11 -0
  26. package/src/file-transfer.ts +173 -0
  27. package/src/index.ts +3 -0
  28. package/src/mapi.ts +1016 -0
  29. package/src/monetize.ts +67 -0
  30. package/test/connection.ts +43 -0
  31. package/test/exec-queries.ts +112 -0
  32. package/test/filetransfer.ts +94 -0
  33. package/test/prepare-statement.ts +27 -0
  34. package/test/query-stream.ts +41 -0
  35. package/test/tmp/.gitignore +4 -0
  36. package/tsconfig.json +24 -0
  37. package/.travis.yml +0 -11
  38. package/dist/mapi.d.ts +0 -58
  39. package/dist/mapi.js +0 -250
  40. package/dist/mapi.js.map +0 -1
  41. package/dist/tsconfig.tsbuildinfo +0 -1
  42. package/foo.js +0 -16
  43. package/index.js +0 -5
  44. package/src/mapi-connection.js +0 -784
  45. package/src/monetdb-connection.js +0 -385
  46. package/src/utils.js +0 -27
  47. package/test/common.js +0 -45
  48. package/test/install-monetdb.sh +0 -11
  49. package/test/monetdb_stream.js +0 -106
  50. package/test/start-monetdb.sh +0 -38
  51. package/test/test.js +0 -908
  52. package/test/test_connection.js +0 -290
  53. /package/docs/{README.v0.md → v0/README.v0.md} +0 -0
  54. /package/docs/{MapiConnection.md → v1/MapiConnection.md} +0 -0
  55. /package/docs/{v1-notes.md → v1/v1-notes.md} +0 -0
@@ -0,0 +1,532 @@
1
+ # MonetDB NodeJS connector version 1.\*
2
+
3
+ [![Linux](https://github.com/MonetDB/monetdb-nodejs/workflows/Linux/badge.svg)
4
+ [![macOS](https://github.com/MonetDB/monetdb-nodejs/workflows/macos/badge.svg)
5
+ [![Travis CI](https://travis-ci.org/MonetDB/monetdb-nodejs.svg)](https://travis-ci.org/MonetDB/monetdb-nodejs)
6
+ [![Coverage Status](https://coveralls.io/repos/MonetDB/monetdb-nodejs/badge.svg?branch=master&service=github)](https://coveralls.io/github/MonetDB/monetdb-nodejs?branch=master)
7
+ [![npm version](https://badge.fury.io/js/monetdb.svg)](https://badge.fury.io/js/monetdb)
8
+
9
+
10
+ This NodeJS module provides an easy and powerful way to use MonetDB inside your NodeJS programs.
11
+
12
+
13
+ For version 0.\* users:
14
+ * **[Click here for documentation of version 0.\*](https://github.com/MonetDB/monetdb-nodejs/blob/master/docs/README.v0.md)**
15
+ * **[Click here for update notes, including new features, backward compatibility notes, and upgrade instructions](https://github.com/MonetDB/monetdb-nodejs/blob/master/docs/v1-notes.md)**
16
+
17
+
18
+ <a name="example"></a>
19
+ ## Example usage
20
+
21
+ ```javascript
22
+ var MDB = require('monetdb')();
23
+
24
+ var options = {
25
+ host : 'localhost',
26
+ port : 50000,
27
+ dbname : 'mydb',
28
+ user : 'monetdb',
29
+ password : 'monetdb'
30
+ };
31
+
32
+ var conn = new MDB(options);
33
+ conn.connect();
34
+
35
+ conn.query('SELECT * FROM mytable').then(function(result) {
36
+ // Do something with the result
37
+ });
38
+
39
+ conn.close();
40
+ ```
41
+
42
+
43
+
44
+ <a name="options"></a>
45
+ # Options
46
+ There are three flavors of setting options:
47
+ 1. providing global options
48
+ 2. providing local options
49
+ 3. changing local options
50
+
51
+ Let's look at how we could use these flavors to setup connections for multiple users:
52
+
53
+ ```javascript
54
+ // We set the global option 'dbname' to 'db', for all connections
55
+ var MDB = require('monetdb')({dbname: 'db'});
56
+
57
+ // We can now create two connections for different users
58
+ // Both connections will use the globally set 'dbname' option
59
+ var conn1 = new MDB({user: 'foo', password: 'bar'});
60
+ var conn2 = new MDB({user: 'dumb', password: '0000'});
61
+
62
+ // Now let's change a local option of conn1
63
+ // (which is only possible for non-connection specific options)
64
+ conn1.option("setMaxReconnects", 1);
65
+ ```
66
+
67
+ In general, the order in which options are consider is:
68
+ 1. local
69
+ 2. global
70
+ 3. default (if available)
71
+
72
+ The MonetDB NodeJS module recognizes many options.
73
+ You do not need to know them all.
74
+ There is **only one** option that does not have a default value, and that is the database name (dbname).
75
+
76
+ The available options can be subdivided into several categories:
77
+
78
+
79
+ ### Connection options
80
+ These options are used to make the actual connection to MonetDB. Note that these options can not be changed with the
81
+ [MonetDBConnection.option](#mdbconnection_option) method.
82
+ If you want to change these settings on an open connection, just construct a new connection.
83
+
84
+ | Option | Type | Default | Additional description |
85
+ | :---------------- | :-------- | :------------------------------ | :--------------------- |
86
+ | host | string | localhost |
87
+ | port | integer | 50000 |
88
+ | dbname | string | | No default value for this one.
89
+ | user | string | monetdb |
90
+ | password | string | monetdb |
91
+ | language | string | sql | The language of the issued queries. Should be one of sql/mal.
92
+ | defaultSchema | string | sys | The default schema to set the connection to after connecting.
93
+ | timezoneOffset | integer | offset of current timezone | The offset in minutes that holds for the required timezone. See [connection timezone](#timezone) for more info.
94
+ | autoCommit | boolean | true | Set auto_commit flag
95
+
96
+
97
+ ### Reconnection options
98
+ These options are used to determine how to reconnect whenever a connection fails.
99
+
100
+ | Option | Type | Default | Additional description |
101
+ | :---------- | :-------- | :------------------------------ | :--------------------- |
102
+ | maxReconnects | integer | 10 | The maximum number of reconnect attempts after a connection failure. Set to 0 if you do not want to reconnect on connection failures.
103
+ | reconnectTimeout | integer | 2000 | The timeout used in between reconnect attempts.
104
+
105
+
106
+ ### Query options
107
+ These options influence the way queries are executed.
108
+
109
+ | Option | Type | Default | Additional description |
110
+ | :---------------- | :-------- | :------------------------------ | :--------------------- |
111
+ | prettyResult | boolean | false | The value for this option will be the default value for how query results are returned. This can be overwritten on a per-query basis. See [pretty results](#pretty) for more info.
112
+
113
+ ### Logging
114
+ The MonetDB NodeJS module comes with a very extensive logging functionality. It distinguishes between many types of different
115
+ messages, and allows you to fully customize the way the MonetDB NodeJS module deals with log messages when they occur.
116
+ See the [logging section](#logging) for more information.
117
+
118
+ | Option | Type | Default | Additional description |
119
+ | :---------------- | :-------- | :------------------------------ | :--------------------- |
120
+ | logger | function | console.log | This function will be used by all of the default logging functions.
121
+ | warnings | boolean | true | Whether or not to log warnings. **It is highly adviced to keep this set to true, otherwise you will not be notified on e.g. unrecognized options or reconnection attempts.**
122
+ | warningFn | function | See [logging section](#logging) | Warning messages will be passed to this function when they occur.
123
+ | debug | boolean | false | Whether or not to log general debug messages.
124
+ | debugFn | function | See [logging section](#logging) | Debug messages will be passed to this function when they occur.
125
+ | debugRequests | boolean | false | Whether or not to log requests (SQL or MAL) when they resolve.
126
+ | debugRequestFn | function | See [logging section](#logging) | SQL or MAL requests, including their results, will be passed to this function when they occur.
127
+ | debugMapi | boolean | false | Whether or not to show the Mapi messages that are being sent back and forth between the MonetDB NodeJS module and the MonetDB server.
128
+ | debugMapiFn | function | See [logging section](#logging) | Mapi messages will be passed to this function when they occur.
129
+
130
+
131
+
132
+ ### Testing
133
+ Options provided solely for testing.
134
+
135
+ | Option | Type | Default | Additional description |
136
+ | :---------------- | :-------- | :------------------------------ | :--------------------- |
137
+ | testing | boolean | false | When set to true, some additional (undocumented) methods will be exposed, e.g. to simulate socket failures.
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+ <a name="mdbconnection"></a>
146
+ # MonetDBConnection
147
+
148
+ Getting a MonetDBConnection object is easy:
149
+
150
+ ```javascript
151
+ var MDB = require('monetdb')();
152
+
153
+ // MDB is a constructor function; let's construct a MonetDBConnection object, shall we?
154
+ var conn = new MDB({dbname: 'mydb'});
155
+
156
+ // conn now is a MonetDBConnection object
157
+ ```
158
+
159
+ All of its exposed attributes and methods are listed here:
160
+
161
+
162
+ <a name="mdbconnection_constructor"></a>
163
+ ### MonetDBConnection(\[options\])
164
+ Constructor for a MonetDBConnection object, that takes an optional options object. For possible options, see the
165
+ [options section](#options).
166
+
167
+ Throws an error when the provided options object is not ok.
168
+
169
+
170
+
171
+ <a name="mdbconnection_mapiconnection"></a>
172
+ ### .mapiConnection
173
+ Instance of MapiConnection. This attribute will be managed by the MonetDBConnection object, so in normal cases you should
174
+ not use this. Only if you want to e.g. fire raw queries against the database, you might want to reference it directly.
175
+ Just in case you are wondering,
176
+ [here is the documentation](https://github.com/MonetDB/monetdb-nodejs/blob/master/docs/MapiConnection.md).
177
+
178
+
179
+
180
+ <a name="mdbconnection_connect"></a>
181
+ ### .connect()
182
+ *This method links to [MapiConnection.connect](https://github.com/MonetDB/monetdb-nodejs/blob/master/docs/MapiConnection.md#connect)*
183
+
184
+ Open the connection to the MonetDB server.
185
+
186
+ Returns a promise that resolves when the connection succeeded, and gets rejected with an error message otherwise.
187
+ Note that you **do not have to wait** for the connection promise to be resolved before issueing queries, since incoming
188
+ queries will be properly cached.
189
+
190
+
191
+
192
+ ### .open()
193
+ Alias for [MonetDBConnection.connect](#mdbconnection_connect).
194
+
195
+
196
+
197
+ <a name="mdbconnection_query"></a>
198
+ ### .query(query, \[params\], \[prettyResult\])
199
+ Issue a query against the database. For a simple example, [see here](#example).
200
+
201
+ | Argument | Type | Required | Description |
202
+ | :------------ | :------------ | :------------- | :-------------- |
203
+ | query | string | yes | The query you want to run. In case language is sql, this should be a valid SQL query.
204
+ | params | array | no | If this array is given, a prepared statement will be used under the hood. Very useful if you want to easily protect against SQL injection.
205
+ | prettyResult | boolean | no | If this is set to true, the query result will be prettified. If not given, the default from the options is used. See the [pretty result section](#pretty) for more info.
206
+
207
+ Example of a query with parameters:
208
+ ```javascript
209
+ var MDB = require('monetdb')();
210
+
211
+ var conn = new MDB({dbname: 'mydb'});
212
+ conn.connect();
213
+
214
+ conn.query(
215
+ 'SELECT * FROM mytable WHERE c < ? AND d > ?',
216
+ [40, 102]
217
+ ).then(function(result) {
218
+ // Do something with the result
219
+ });
220
+ ```
221
+
222
+ Returns a promise that resolves with an object with the following properties:
223
+
224
+ | Property | Type | Description |
225
+ | :--------------------- | :--------------------- | :-------------- |
226
+ | data | array\[array\|object\] | If this is the result of a SELECT query, this property contains the resulting data returned by the database. Every array entry represents one row of the result set. If the 'prettyResult' option was set to true, every array entry will be an object, where the object properties equal the column names. Otherwise, the array entries will be arrays containing just the column values.
227
+ | col | object | Object maps column names to query result indices. So if you for example did SELECT a, b FROM ... you can access b in a tuple array by issuing tuple[result.col.b], which in this case would resolve to tuple[1].
228
+ | rows | integer | The number of rows in the result set.
229
+ | cols | integer | The number of columns in the result set.
230
+ | structure | array\[object\] | An array containing an object for every column, with column information.
231
+ | structure\[i\].table | string | The name of the table to which column i belongs.
232
+ | structure\[i\].column | string | The name of column i.
233
+ | structure\[i\].type | string | The database type of column i.
234
+ | structure\[i\].typelen | integer | The length in the database of column i.
235
+ | structure\[i\].index | index | The array index of column i, which will equal i.
236
+ | queryid | integer | A unique identifier for this query.
237
+ | type | string | The type of the result (currently only 'table' is supported).
238
+
239
+
240
+ ### .querystream(query)
241
+ Stream monetdb response.
242
+
243
+ Example:
244
+ ```javascript
245
+ var MDB = require('monetdb')();
246
+
247
+ var conn = new MDB({dbname: 'mydb'});
248
+ conn.connect();
249
+
250
+ function test_stream (conn, sql) {
251
+ let result;
252
+ return new Promise((resolve, reject) => {
253
+ conn.querystream(sql)
254
+ .on('error', (err) => {
255
+ return reject(err);
256
+ })
257
+ .on('header', (header) => {
258
+ "add header to result"
259
+
260
+ })
261
+ .on('data', (data) => {
262
+ "add data to result"
263
+ })
264
+ .on('end', () => {
265
+ "all rows being received"
266
+ resolve(result);
267
+ });
268
+ });
269
+ }
270
+ ```
271
+
272
+ ### .request(query, \[params\], \[prettyResult\])
273
+ Alias for [MonetDBConnection.query](#mdbconnection_query).
274
+
275
+
276
+
277
+ <a name="mdbconnection_prepare"></a>
278
+ ### .prepare(query, \[prettyResult\])
279
+ Prepares a query for repeated execution, and generates execution and release convenience functions.
280
+
281
+ | Argument | Type | Required | Description |
282
+ | :------------ | :------------ | :------------- | :-------------- |
283
+ | query | string | yes | The query that has to be prepared. If it does not start with prepare (case insensitive), 'PREPARE ' will be prepended to the query.
284
+ | prettyResult | boolean | no | If this is set to true, the exec function will return prettified results. If not given, the default from the options is used. See the [pretty result section](#pretty) for more info.
285
+
286
+ Returns a promise that resolves with an object with the following properties:
287
+
288
+ | Property | Type | Description |
289
+ | :--------------------- | :----------- | :-------------- |
290
+ | prepare | object | The regular query result for the PREPARE statement, as is described under [MonetDBConnection.query](#mdbconnection_query).
291
+ | exec | function | A function that executes the prepared statement. As its first and only argument, it takes an array of values. It returns a promise equivalent to the promise returned by [MonetDBConnection.query](#mdbconnection_query).
292
+ | release | function | A parameterless function that you can call when you want to free the resources used by the prepared statement. After calling this function, calls to the exec function will fail. This function **does not** return anything. You cannot be notified of whether or not this worked.
293
+
294
+ Example:
295
+
296
+ ```javascript
297
+ var MDB = require('monetdb')();
298
+
299
+ var conn = new MDB({dbname: 'mydb'});
300
+ conn.connect();
301
+
302
+ conn.prepare('SELECT * FROM mytable WHERE c < ? AND d > ?').then(function(prepResult) {
303
+ // execute query twice
304
+ prepResult.exec([10, 5]).then(function(result) {
305
+ // do something with the result
306
+ });
307
+ prepResult.exec([50, -20]).then(function(result) {
308
+ // do something with the result
309
+ });
310
+
311
+ // we are done, release it (and do not wait for it, release method does not return a promise)
312
+ prepResult.release();
313
+ });
314
+ ```
315
+
316
+
317
+ <a name="mdbconnection_env"></a>
318
+ ### .env()
319
+ Get the connection environment. Example:
320
+
321
+ ```javascript
322
+ var MDB = require('monetdb')();
323
+
324
+ var conn = new MDB({dbname: 'mydb'});
325
+ conn.connect();
326
+
327
+ conn.env().then(function(env) {
328
+ console.log(env);
329
+ });
330
+ ```
331
+
332
+ Will output:
333
+
334
+ ```
335
+ {
336
+ "gdk_dbpath": "/home/robin/dbfarm/test",
337
+ "gdk_debug": "0",
338
+ "gdk_vmtrim": "no",
339
+ ..
340
+ ```
341
+
342
+
343
+ <a name="mdbconnection_option"></a>
344
+ ### .option(name, [value])
345
+ Get or set an option.
346
+
347
+ | Argument | Type | Required | Description |
348
+ | :------------ | :------------------ | :------------- | :-------------- |
349
+ | name | string | yes | The name of the option. See the [option section](#options) for the recognized options.
350
+ | value | depending on option | no | If this argument is provided, it is assumed that you want to set the option to this argument. Note that setting options is not possible for connection options. The connection options are mentioned in the [option section](#options).
351
+
352
+ Throws an error if either the provided option is not found, or if the provided value is invalid.
353
+
354
+ If the second argument is omitted, the value of the option is returned.
355
+
356
+
357
+ <a name="mdbconnection_getstate"></a>
358
+ ### .getState()
359
+ *This method links to [MapiConnection.getState](https://github.com/MonetDB/monetdb-nodejs/blob/master/docs/MapiConnection.md#getstate)*
360
+
361
+ Get the current state of the connection. For normal usage you will never need to use this.
362
+
363
+ Returns one of the following state strings:
364
+
365
+ | State | Meaning |
366
+ | :------------ | :------------ |
367
+ | disconnected | There is currently no open connection, either because it has never been opened yet, or because a reconnect is going on.
368
+ | connected | There is an open connection to the server, but authentication has not finished yet.
369
+ | ready | There is an open connection to the server, and we have successfully authenticated. The connection is ready to accept queries.
370
+ | destroyed | The connection is destroyed, either because it was explicitly destroyed by a call to [MonetDBConnection.destroy](#mdbconnection_destroy), or because of a failure to keep the connection open.
371
+
372
+ Regardless of the return value of this method, you can safely issue queries to the connection, since they will be properly queued until the connection is ready.
373
+
374
+
375
+
376
+ <a name="mdbconnection_close"></a>
377
+ ### .close()
378
+ *This method links to [MapiConnection.close](https://github.com/MonetDB/monetdb-nodejs/blob/master/docs/MapiConnection.md#close)*
379
+
380
+ Finishes all the current queries in the queue, and then destroys the socket by calling [MonetDBConnection.destroy](#mdbconnection_destroy).
381
+ After closing a connection, it cannot be reopened. If reopening is desired, you should create a [new MonetDBConnection object](#mdbconnection_constructor).
382
+
383
+ When queries are issued after calling close, they are still accepted and put into the queue, so a connection remains active
384
+ until it becomes idle.
385
+
386
+ Note that when you have issued a query with parameters, this will under the hood be executed in two steps (one prepare step
387
+ and one execution step). If the close method is called after firing a prepared statement, it might therefore fail because the
388
+ socket can be destroyed after finishing the first step.
389
+
390
+ Returns a promise that resolves when all queries in the queue are done and the socket is destroyed.
391
+
392
+
393
+
394
+ ### .disconnect()
395
+ Alias for [MonetDBConnection.close](#mdbconnection_close).
396
+
397
+
398
+
399
+ <a name="mdbconnection_destroy"></a>
400
+ ### .destroy(\[msg\])
401
+ *This method links to [MapiConnection.destroy](https://github.com/MonetDB/monetdb-nodejs/blob/master/docs/MapiConnection.md#destroy)*
402
+
403
+ Fails all queries currently in the queue (including the one that is currently being executed), and destroys the socket.
404
+
405
+ | Argument | Type | Required | Description |
406
+ | :------------ | :------------------ | :------------- | :-------------- |
407
+ | msg | string | no | An error message that will be sent to all queries that are rejected. If none is given, a default error message is sent.
408
+
409
+
410
+ ### .getCallbackWrapper()
411
+ This method is added for backward compatability. For information on how to use it, see
412
+ [the updates page](https://github.com/MonetDB/monetdb-nodejs/blob/master/docs/update.md#callbackwrapper).
413
+
414
+
415
+
416
+ <a name="pretty"></a>
417
+ # Pretty query results
418
+ By default, every row in a query result is represented by an array. However, if the pretty flag is set, the query result
419
+ will instead be an array of objects, where every object has the column names as its properties. This makes using the result
420
+ a lot more intuitive and fault-tolerant (e.g. if you hard code indices into row arrays, your code might start failing
421
+ when you change the SQL query).
422
+ The default value of the pretty flag can be overwritten by providing the global or local option 'prettyResult'. Even then,
423
+ you can override this default value on a per query basis, by providing a boolean value as last argument to either the
424
+ [MonetDBConnection.query](#mdbconnection_query) or the [MonetDBConnection.prepare](#mdbconnection_prepare) function.
425
+ Example:
426
+
427
+ ```javascript
428
+ var MDB = require('monetdb')();
429
+
430
+ var conn = new MDB({dbname: 'mydb'});
431
+ conn.connect();
432
+
433
+ // we did not set the option 'prettyResult', hence we will pass true to our queries to have them return prettified results.
434
+ conn.query("SELECT a, b FROM yourtable").then(function(result) {
435
+ console.log(result.data);
436
+ });
437
+ ```
438
+
439
+ Outputs (depending on the values of columnns a and b and the number of resulting tuples):
440
+ ```
441
+ [
442
+ { a: 'val1', b: 'val2' },
443
+ { a: 'val3', b: 'val4' }
444
+ ]
445
+ ```
446
+
447
+
448
+
449
+ <a name="timezone"></a>
450
+ # Connection time zone
451
+ For every connection that is opened to the server, the timezone is automatically set to the current timezone of the system
452
+ that opens the connection. You can change this behavior by passing a value for the [option 'timezoneOffset'](#options).
453
+ The value for this option represents the number of minutes to deviate from GMT.
454
+ This value is used by MonetDB to present timestamps with timezone. Example:
455
+
456
+ ```javascript
457
+ var MDB = require('monetdb')();
458
+
459
+ // Create two connections with different time zone
460
+
461
+ // One GMT+02:00
462
+ var conn1 = new MDB({timezoneOffset: 120, dbname: 'mydb'});
463
+
464
+ // And one GMT-03:30 (= -210 minutes)
465
+ var conn2 = new MDB({timezoneOffset: -210, dbname: 'mydb'});
466
+
467
+ conn1.connect();
468
+ conn2.connect();
469
+
470
+ conn1.query('SELECT NOW').then(function(result) {
471
+ // result.data[0][0] will be something like '2015-11-02 08:11:31.000000+02:00'
472
+ });
473
+
474
+ conn2.query('SELECT NOW').then(function(result) {
475
+ // result.data[0][0] will be something like '2015-11-02 02:45:56.000000-03:30'
476
+ });
477
+ ```
478
+
479
+
480
+
481
+ <a name="logging"></a>
482
+ # Logging
483
+ As you can see from the [options section](#options), there are many logging options. By default, only warning messages
484
+ are logged, and console.log is used for this. The following types of log events can occur:
485
+ 1. Warnings
486
+ * Unrecognized options
487
+ * Connection failures
488
+ * Queries are issued before calling [connect()](#mdbconnection_connect)
489
+ 2. Debug messages
490
+ * State changes (see
491
+ [MapiConnection object](https://github.com/MonetDB/monetdb-nodejs/blob/master/docs/MapiConnection.md#getstate)
492
+ for possible states)
493
+ * Read/write counts on opened socket
494
+ 3. Resolved requests
495
+ 4. Mapi messages
496
+
497
+ You can manipulate whether or not these events are logged or not, and which functions are used to do this.
498
+ For all of these events, a default log function is specified in
499
+ [utils.js](https://github.com/MonetDB/monetdb-nodejs/blob/master/src/utils.js)
500
+ Every log function receives as its first argument the logger that it should use, where the logger simply
501
+ takes a string and logs it somewhere. By default, the logger is **console.log**. You can change this in
502
+ the [options](#options).
503
+
504
+ In case you want to overwrite the default log functions, here are the function signatures:
505
+
506
+ ### options.warningFn(logger, msg)
507
+
508
+ | Argument | Type | Description |
509
+ | :------------ | :------------------- | :-------------- |
510
+ | logger | function | The logger that is used, which defaults to console.log but can be specified through the [options](#options).
511
+ | msg | string | The message to write to the provided logger.
512
+
513
+ ### options.debugFn(logger, msg)
514
+ Same as options.warningFn
515
+
516
+ ### options.debugRequestFn(logger, request, error, result)
517
+
518
+ | Argument | Type | Description |
519
+ | :------------ | :------------------- | :-------------- |
520
+ | logger | function | The logger that is used, which defaults to console.log but can be specified through the [options](#options).
521
+ | request | string | The request message (SQL query string in case this request is an SQL query)
522
+ | error | Error|null | If this request failed, this argument contains the error that was thrown. Otherwise, this argument will be null.
523
+ | result | Object|null | If this request passed, this argument contains the [resulting object](#mdbconnection_query).
524
+
525
+ ### options.debugMapiFn(logger, type, msg)
526
+
527
+ | Argument | Type | Description |
528
+ | :------------ | :------------------- | :-------------- |
529
+ | logger | function | The logger that is used, which defaults to console.log but can be specified through the [options](#options).
530
+ | type | string | Either 'TX' for transmitted messages, or 'RX' for received messages.
531
+ | msg | string | The string that was communicated over the socket.
532
+
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
1
  {
2
2
  "name": "monetdb",
3
- "version": "1.3.4",
4
- "description": "Connect MonetDB to your NodeJS app",
5
- "main": "index.js",
3
+ "version": "2.0.1",
4
+ "description": "Connect MonetDB to your Node.js app",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
6
7
  "scripts": {
7
- "test": "`npm bin`/mocha --exit",
8
- "coverage": "`npm bin`/istanbul cover `npm bin`/_mocha --report lcovonly -- -R spec Tests/test.js",
9
- "coveralls": "npm run-script coverage && node node_modules/coveralls/bin/coveralls.js < coverage/lcov.info"
8
+ "build": "tsc",
9
+ "test": "mocha -r ts-node/register test/**/*.ts"
10
10
  },
11
11
  "keywords": [
12
12
  "monetdb"
13
13
  ],
14
14
  "author": {
15
- "name": "Robin Cijvat",
16
- "email": "robin.cijvat@monetdbsolutions.com"
15
+ "name": "Svetlin Stalinov",
16
+ "email": "svetlin.stalinov@monetdbsolutions.com"
17
17
  },
18
18
  "contributors": [
19
19
  {
20
- "name": "Hannes Mühleisen",
21
- "email": "hannes@cwi.nl"
20
+ "name": "Robin Cijvat",
21
+ "email": "robin.cijvat@monetdbsolutions.com"
22
22
  },
23
23
  {
24
- "name": "Svetlin Stalinov",
25
- "email": "svetlin.stalinov@monetdbsolutions.com"
24
+ "name": "Hannes Mühleisen",
25
+ "email": "hannes@cwi.nl"
26
26
  }
27
27
  ],
28
28
  "repository": {
@@ -31,14 +31,10 @@
31
31
  },
32
32
  "license": "SEE LICENSE IN LICENSE",
33
33
  "devDependencies": {
34
- "chai": "^3.4.0",
35
- "chai-as-promised": "^5.1.0",
36
- "coveralls": "^3.0.9",
37
- "istanbul": "^0.4.0",
34
+ "@types/mocha": "^10.0.1",
35
+ "@types/node": "^18.11.17",
38
36
  "mocha": "^10.2.0",
39
- "mocha-lcov-reporter": "^1.0.0"
40
- },
41
- "dependencies": {
42
- "q": "^1.4.1"
37
+ "ts-node": "^10.9.1",
38
+ "typescript": "^4.9.4"
43
39
  }
44
40
  }
@@ -0,0 +1,37 @@
1
+ import { MapiConnection, QueryResult } from './mapi';
2
+ import { convert } from './monetize';
3
+
4
+ class PrepareStatement {
5
+ id: number;
6
+ rowCnt: number;
7
+ columnCnt: number;
8
+ mapi: MapiConnection;
9
+ data: any[];
10
+ constructor(res: QueryResult, mapi: MapiConnection) {
11
+ this.id = res.id;
12
+ this.rowCnt = res.rowCnt;
13
+ this.columnCnt = res.columnCnt;
14
+ this.data = res.data; // columns and placeholder columns info
15
+ this.mapi = mapi;
16
+ }
17
+
18
+ execute(...args: any[]): Promise<any> {
19
+ const colInfo = this.data.slice(-args.length);
20
+ const placeholders = args.map((arg, i) => {
21
+ const type = colInfo[i][0];
22
+ const digits = colInfo[i][1];
23
+ const scale = colInfo[i][2];
24
+ return convert(type, arg, digits, scale);
25
+ })
26
+ const query = `sEXECUTE ${this.id}(${placeholders.join(', ')});\n`;
27
+ return this.mapi.request(query);
28
+ }
29
+
30
+ release(): Promise<any> {
31
+ const stmt = `sDEALLOCATE ${this.id};\n`;
32
+ return this.mapi.request(stmt);
33
+ }
34
+
35
+ }
36
+
37
+ export default PrepareStatement;