@bkmj/node-red-contrib-odbcmj 1.6.5 → 1.7.0

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 (4) hide show
  1. package/README.md +18 -113
  2. package/odbc.html +226 -146
  3. package/odbc.js +623 -193
  4. package/package.json +1 -1
package/odbc.html CHANGED
@@ -1,268 +1,348 @@
1
1
  <script type="text/javascript">
2
- RED.nodes.registerType('odbc config',{
3
- category: 'config',
2
+ RED.nodes.registerType("odbc config", {
3
+ category: "config",
4
4
  defaults: {
5
- connectionString: {value:"", required:true},
6
- name: {value:""},
7
- initialSize: {value:5},
8
- incrementSize: {value:5},
9
- maxSize: {value:15},
10
- shrink:{value:true},
11
- syntaxtick:{value:false},
12
- syntax: {value:"mysql"},
13
- connectionTimeout:{value:3},
14
- loginTimeout:{value:3}
5
+ connectionString: { value: "", required: true },
6
+ name: { value: "" },
7
+ initialSize: { value: 5 },
8
+ incrementSize: { value: 5 },
9
+ maxSize: { value: 15 },
10
+ shrink: { value: true },
11
+ syntaxtick: { value: false },
12
+ syntax: { value: "mysql" },
13
+ connectionTimeout: { value: 3 },
14
+ loginTimeout: { value: 3 },
15
+ // NOUVELLE PROPRIÉTÉ AJOUTÉE ICI
16
+ retryFreshConnection: { value: false }, // Default à false
15
17
  },
16
- label: function() {
17
- return this.name || 'odbc config';
18
+ label: function () {
19
+ return this.name || "odbc config";
18
20
  },
19
- oneditprepare: function() {
21
+ oneditprepare: function () {
20
22
  $(".input-syntax").hide();
21
- $("#node-config-input-syntaxtick").change(function() {
22
- if (this.checked){
23
+ $("#node-config-input-syntaxtick").change(function () {
24
+ if (this.checked) {
23
25
  $(".input-syntax").show();
24
26
  } else {
25
27
  $(".input-syntax").hide();
26
28
  }
27
29
  });
28
- }
30
+ },
29
31
  });
30
32
  </script>
31
33
 
32
34
  <script type="text/html" data-template-name="odbc config">
35
+ <div class="form-row">
36
+ <label for="node-config-input-name"
37
+ ><i class="fa fa-tag"></i> Name</label
38
+ >
39
+ <input type="text" id="node-config-input-name" />
40
+ </div>
33
41
 
34
42
  <div class="form-row">
35
- <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
36
- <input type="text" id="node-config-input-name">
43
+ <label for="node-config-input-connectionString"
44
+ ><i class="fa fa-database"></i> Connection String</label
45
+ >
46
+ <input
47
+ type="text"
48
+ id="node-config-input-connectionString"
49
+ placeholder="DSN=...;"
50
+ />
37
51
  </div>
38
52
 
39
53
  <div class="form-row">
40
- <label for="node-config-input-connectionString"><i class="icon-bookmark"></i>Connection String</label>
41
- <input type="text" id="node-config-input-connectionString" placeholder="DSN=...;">
54
+ <label for="node-config-input-initialSize"
55
+ ><i class="fa fa-play"></i> Initial Size</label
56
+ >
57
+ <input
58
+ type="number"
59
+ id="node-config-input-initialSize"
60
+ placeholder="5"
61
+ />
42
62
  </div>
43
63
 
44
64
  <div class="form-row">
45
- <label for="node-config-input-initialSize"><i class="icon-bookmark"></i>Initial Size</label>
46
- <input type="number" id="node-config-input-initialSize" placeholder="5">
65
+ <label for="node-config-input-incrementSize"
66
+ ><i class="fa fa-plus"></i> Increment Size</label
67
+ >
68
+ <input
69
+ type="number"
70
+ id="node-config-input-incrementSize"
71
+ placeholder="5"
72
+ />
47
73
  </div>
48
74
 
49
75
  <div class="form-row">
50
- <label for="node-config-input-incrementSize"><i class="icon-bookmark"></i>Increment Size</label>
51
- <input type="number" id="node-config-input-incrementSize" placeholder="5">
76
+ <label for="node-config-input-maxSize"
77
+ ><i class="fa fa-stop"></i> Max Size</label
78
+ >
79
+ <input type="number" id="node-config-input-maxSize" placeholder="15" />
52
80
  </div>
53
81
 
54
82
  <div class="form-row">
55
- <label for="node-config-input-maxSize"><i class="icon-bookmark"></i>Max Size</label>
56
- <input type="number" id="node-config-input-maxSize" placeholder="15">
83
+ <label for="node-config-input-shrink"
84
+ ><i class="fa fa-compress"></i> Shrink Pool</label
85
+ >
86
+ <input
87
+ type="checkbox"
88
+ id="node-config-input-shrink"
89
+ style="margin-left:0px; vertical-align:top; width:auto !important;"
90
+ />
57
91
  </div>
58
92
 
59
93
  <div class="form-row">
60
- <label for="node-config-input-shrink"><i class="icon-bookmark"></i>Shrink Pool</label>
61
- <input type="checkbox" id="node-config-input-shrink" style="margin-left:0px; vertical-align:top; width:auto !important;">
94
+ <label for="node-config-input-connectionTimeout"
95
+ ><i class="fa fa-clock-o"></i></i> Connection Timeout (sec)</label
96
+ >
97
+ <input
98
+ type="number"
99
+ id="node-config-input-connectionTimeout"
100
+ placeholder="3"
101
+ />
62
102
  </div>
63
103
 
64
104
  <div class="form-row">
65
- <label for="node-config-input-connectionTimeout"><i class="icon-bookmark"></i>Connection Timeout (sec)</label>
66
- <input type="number" id="node-config-input-connectionTimeout" placeholder="3">
105
+ <label for="node-config-input-loginTimeout"
106
+ ><i class="fa fa-clock-o"></i> Login Timeout (sec)</label
107
+ >
108
+ <input
109
+ type="number"
110
+ id="node-config-input-loginTimeout"
111
+ placeholder="3"
112
+ />
67
113
  </div>
68
114
 
69
115
  <div class="form-row">
70
- <label for="node-config-input-loginTimeout"><i class="icon-bookmark"></i>Login Timeout (sec)</label>
71
- <input type="number" id="node-config-input-loginTimeout" placeholder="3">
116
+ <label for="node-config-input-retryFreshConnection" style="width: auto;"
117
+ ><i class="fa fa-refresh"></i> Retry with fresh connection on
118
+ error</label
119
+ >
120
+ <input
121
+ type="checkbox"
122
+ id="node-config-input-retryFreshConnection"
123
+ style="display: inline-block; width: auto; vertical-align: top;"
124
+ />
72
125
  </div>
73
126
 
74
127
  <div class="form-row">
75
- <label for="node-config-input-syntaxtick" style="width: auto;"><i class="icon-bookmark"></i>Syntax Checker</label>
76
- <input type="checkbox" id="node-config-input-syntaxtick" style="display: inline-block; width: auto; vertical-align: top;">
128
+ <label for="node-config-input-syntaxtick" style="width: auto;"
129
+ ><i class="fa fa-underline"></i> Syntax Checker</label
130
+ >
131
+ <input
132
+ type="checkbox"
133
+ id="node-config-input-syntaxtick"
134
+ style="display: inline-block; width: auto; vertical-align: top;"
135
+ />
77
136
  </div>
78
137
 
79
138
  <div class="form-row input-syntax">
80
- <label for=""><i class="icon-bookmark"></i> Syntax</label>
139
+ <label for="node-config-input-syntax"
140
+ ><i class="fa fa-language"></i> Syntax</label
141
+ >
81
142
  <select id="node-config-input-syntax" style="width: 70%">
82
- <option value="bigquery">BigQuery</option>
83
- <option value="db2">DB2</option>
84
- <option value="hive">Hive</option>
85
- <option value="mariadb">MariaDB</option>
86
- <option value="mysql">Mysql</option>
87
- <option value="postgresql">PostgresQL</option>
88
- <option value="sqlite">Sqlite</option>
89
- <option value="transactsql">TransactSQL</option>
90
- <option value="flinksql">FlinkSQL</option>
143
+ <option value="bigquery">BigQuery</option>
144
+ <option value="db2">DB2</option>
145
+ <option value="hive">Hive</option>
146
+ <option value="mariadb">MariaDB</option>
147
+ <option value="mysql">Mysql</option>
148
+ <option value="postgresql">PostgresQL</option>
149
+ <option value="sqlite">Sqlite</option>
150
+ <option value="transactsql">TransactSQL</option>
151
+ <option value="flinksql">FlinkSQL</option>
91
152
  </select>
92
153
  </div>
93
154
  </script>
94
155
 
95
156
  <script type="text/javascript">
96
- RED.nodes.registerType('odbc',{
97
- category: 'storage',
98
- color: '#89A5C0',
99
- defaults: {
100
- name: {value:""},
101
- connection: {type:"odbc config", required:true},
102
- query: {value: ""},
103
- outputObj: {value:"payload"}
104
- },
105
- inputs:1,
106
- outputs:1,
107
- icon: "db.svg",
108
- label: function() {
109
- return this.name||"odbc";
110
- },
111
- oneditprepare: function() {
112
- this.editor = RED.editor.createEditor({
113
- id: 'node-input-query-editor',
114
- mode: 'ace/mode/sql',
115
- value: this.query
116
- });
117
- },
118
- oneditsave: function() {
119
- this.query = this.editor.getValue();
120
- this.editor.destroy();
121
- delete this.editor;
122
- },
123
- oneditcancel: function() {
124
- this.editor.destroy();
125
- delete this.editor;
126
- }
127
- });
157
+ RED.nodes.registerType("odbc", {
158
+ category: "storage",
159
+ color: "#89A5C0",
160
+ defaults: {
161
+ name: { value: "" },
162
+ connection: { type: "odbc config", required: true },
163
+ query: { value: "" },
164
+ outputObj: { value: "payload" },
165
+ },
166
+ inputs: 1,
167
+ outputs: 1,
168
+ icon: "db.svg",
169
+ label: function () {
170
+ return this.name || "odbc";
171
+ },
172
+ oneditprepare: function () {
173
+ this.editor = RED.editor.createEditor({
174
+ id: "node-input-query-editor",
175
+ mode: "ace/mode/sql",
176
+ value: this.query,
177
+ });
178
+ },
179
+ oneditsave: function () {
180
+ this.query = this.editor.getValue();
181
+ this.editor.destroy();
182
+ delete this.editor;
183
+ },
184
+ oneditcancel: function () {
185
+ this.editor.destroy();
186
+ delete this.editor;
187
+ },
188
+ });
128
189
  </script>
129
190
 
130
191
  <script type="text/html" data-template-name="odbc">
131
-
132
192
  <div class="form-row">
133
193
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
134
- <input type="text" id="node-input-name">
194
+ <input type="text" id="node-input-name" />
135
195
  </div>
136
196
 
137
197
  <div class="form-row">
138
- <label for="node-input-connection"><i class="fa fa-cog"></i> Connection</label>
139
- <input type="text" id="node-input-connection">
198
+ <label for="node-input-connection"
199
+ ><i class="fa fa-cog"></i> Connection</label
200
+ >
201
+ <input type="text" id="node-input-connection" />
140
202
  </div>
141
203
 
142
204
  <div class="form-row node-text-editor-row">
143
- <label for="node-input-query" style="width: 100% !important;"><i class="fa fa-search"></i> Query</label>
144
- <div style="height: 250px;" class="node-text-editor" id="node-input-query-editor" ></div>
205
+ <label for="node-input-query" style="width: 100% !important;"
206
+ ><i class="fa fa-search"></i> Query</label
207
+ >
208
+ <div
209
+ style="height: 250px;"
210
+ class="node-text-editor"
211
+ id="node-input-query-editor"
212
+ ></div>
145
213
  </div>
146
214
 
147
215
  <div class="form-row">
148
- <label for="node-input-outputObj"><i class="fa fa-edit"></i> Result to</label>
149
- <span>msg.</span><input type="text" id="node-input-outputObj" placeholder="payload" style="width: 64%;">
216
+ <label for="node-input-outputObj"
217
+ ><i class="fa fa-edit"></i> Result to</label
218
+ >
219
+ <span>msg.</span
220
+ ><input
221
+ type="text"
222
+ id="node-input-outputObj"
223
+ placeholder="payload"
224
+ style="width: 64%;"
225
+ />
150
226
  </div>
151
227
  </script>
152
228
  <script type="text/markdown" data-help-name="odbc config">
153
- A configuration node that manages connections in an `odbc.pool` object.
154
- [Can take any configuration property recognized by `odbc.pool()`](https://www.npmjs.com/package/odbc/v/2.4.8#constructor-odbcconnectconnectionstring).
155
- The connection pool will initialize the first time an `odbc` node receives an input message.
229
+ A configuration node that manages connections in an `odbc.pool` object.
230
+ [Can take any configuration property recognized by `odbc.pool()`](https://www.npmjs.com/package/odbc/v/2.4.8#constructor-odbcconnectconnectionstring).
231
+ The connection pool will initialize the first time an `odbc` node receives an input message.
156
232
 
157
- ## Properties
233
+ ## Properties
158
234
 
159
- * (**required**) **`connectionString`**: <`string`>
235
+ - (**required**) **`connectionString`**: <`string`>
160
236
 
161
- An ODBC connection string that defines your DSN and/or connection string options.
162
- Check your ODBC driver documentation for more information about valid connection strings.
237
+ An ODBC connection string that defines your DSN and/or connection string options.
238
+ Check your ODBC driver documentation for more information about valid connection strings.
163
239
 
164
- Example:
165
- ```
166
- DSN=MyDSN;DFT=2;
167
- ```
240
+ Example:
168
241
 
169
- * (optional) **`initialSize`**: <`number`>
242
+ ```
243
+ DSN=MyDSN;DFT=2;
244
+ ```
170
245
 
171
- The number of connections created in the pool when it is initialized. Default: 5.
246
+ - (optional) **`initialSize`**: <`number`>
172
247
 
173
- * (optional) **`incrementSize`**: <`number`>
248
+ The number of connections created in the pool when it is initialized. Default: 5.
174
249
 
175
- The number of connections that are created when the pool is exhausted. Default: 5.
250
+ - (optional) **`incrementSize`**: <`number`>
176
251
 
177
- * (optional) **`maxSize`**: <`number`>
252
+ The number of connections that are created when the pool is exhausted. Default: 5.
178
253
 
179
- The maximum number of connections allowed in the pool before it won't create any more. Default: 15.
254
+ - (optional) **`maxSize`**: <`number`>
180
255
 
181
- * (optional) **`shrinkPool`**: <`boolean`>
256
+ The maximum number of connections allowed in the pool before it won't create any more. Default: 15.
182
257
 
183
- Whether the number of connections should be reduced to `initialSize` when they are returned to the pool. Default: true.
258
+ - (optional) **`shrinkPool`**: <`boolean`>
184
259
 
185
- * (optional) **`connectionTimeout`**: <`number`>
260
+ Whether the number of connections should be reduced to `initialSize` when they are returned to the pool. Default: true.
186
261
 
187
- The number of seconds for a connection to remain idle before closing. Default: 3.
262
+ - (optional) **`connectionTimeout`**: <`number`>
188
263
 
189
- * (optional) **`loginTimeout`**: <`number`>
264
+ The number of seconds for a connection to remain idle before closing. Default: 3.
190
265
 
191
- The number of seconds for an attempt to create a connection before returning to the application. Default: 3.
266
+ - (optional) **`loginTimeout`**: <`number`>
192
267
 
193
- * (optional) **`syntaxChecker`**: <`boolean`>
268
+ The number of seconds for an attempt to create a connection before returning to the application. Default: 3.
194
269
 
195
- Whether the syntax validator is activated or not. If activated, the query string will be
196
- [parsed](https://www.npmjs.com/package/node-sql-parser#create-ast-for-sql-statement)
197
- and appended as an object to the output message with a key named `parsedQuery`. Default: false.
270
+ - (optional) **`retryFreshConnection`**: <`boolean`> If checked, in case of a query error, the node will attempt the query a second time using a brand new database connection instead of one from the pool. If this second attempt is successful, it indicates the pooled connection was faulty, and the entire connection pool will be reset. Default: false.
198
271
 
199
- * (optional) **`syntax`**: <`string`>
272
+ - (optional) **`syntaxChecker`**: <`boolean`>
200
273
 
201
- Dropdown list of the available [SQL flavors available](https://www.npmjs.com/package/node-sql-parser#supported-database-sql-syntax).
202
- Default: mysql.
274
+ Whether the syntax validator is activated or not. If activated, the query string will be
275
+ [parsed](https://www.npmjs.com/package/node-sql-parser#create-ast-for-sql-statement)
276
+ and appended as an object to the output message with a key named `parsedQuery`. Default: false.
277
+
278
+ - (optional) **`syntax`**: <`string`>
279
+
280
+ Dropdown list of the available [SQL flavors available](https://www.npmjs.com/package/node-sql-parser#supported-database-sql-syntax).
281
+ Default: mysql.
203
282
  </script>
204
283
 
205
284
  <script type="text/markdown" data-help-name="odbc">
206
- A node that runs a query when input is received. Each instance of the node can define its own query string,
207
- as well as take a query and/or parameters as input. A query sent as an input message will override any query
285
+ A node that runs a query when input is received. Each instance of the node can define its own query string,
286
+ as well as take a query and/or parameters as input. A query sent as an input message will override any query
208
287
  defined in the node properties.
209
288
 
210
289
  ## Properties
211
290
 
212
- * (**required**) **`connection`**: <`odbc config`>
291
+ - (**required**) **`connection`**: <`odbc config`>
213
292
 
214
293
  The ODBC pool node that defines the connection settings and manages the connection pool used by this node.
215
294
 
216
- * (optional) **`query`**: <`string`>
295
+ - (optional) **`query`**: <`string`>
217
296
 
218
- A valid SQL query string.
219
- * Can contain parameters inserted using Mustache syntax (e.g., `{{{payload}}}`).
220
- * Can use placeholders (`?`) for parameters.
221
- * Can embed parameters directly in the query string.
297
+ A valid SQL query string.
222
298
 
223
- * (**required**) **`result to`**: <`dot-notation string`>
299
+ - Can contain parameters inserted using Mustache syntax (e.g., `{{{payload}}}`).
300
+ - Can use placeholders (`?`) for parameters.
301
+ - Can embed parameters directly in the query string.
224
302
 
225
- The JSON nested element structure that will contain the result output. The string must be a valid
226
- JSON object structure using dot-notation, minus the `msg.` (e.g., `payload.results`) and must not
227
- start or end with a period. Square bracket notation is not allowed. The node input object is carried
228
- out to the output, as long as the output object name does not conflict with it. If the targeted output
229
- JSON object was already present in the input, the result from the query will be appended to it if it
303
+ - (**required**) **`result to`**: <`dot-notation string`>
304
+
305
+ The JSON nested element structure that will contain the result output. The string must be a valid
306
+ JSON object structure using dot-notation, minus the `msg.` (e.g., `payload.results`) and must not
307
+ start or end with a period. Square bracket notation is not allowed. The node input object is carried
308
+ out to the output, as long as the output object name does not conflict with it. If the targeted output
309
+ JSON object was already present in the input, the result from the query will be appended to it if it
230
310
  was itself an object (but not an array); otherwise, the original key/value pair will be overwritten.
231
311
 
232
312
  Example:
233
313
 
234
- * `input msg: {"payload": {"result": {"othervalue": 10} } };`
235
- * `result to: payload.results.values`
314
+ - `input msg: {"payload": {"result": {"othervalue": 10} } };`
315
+ - `result to: payload.results.values`
236
316
 
237
- In this case, `values` will be appended to `result` without overwriting `othervalue`.
317
+ In this case, `values` will be appended to `result` without overwriting `othervalue`.
238
318
  If `result` had been a string, then it would have been replaced by `values`.
239
319
 
240
320
  ## Inputs
241
321
 
242
322
  The `odbc` node accepts a message input that can contain:
243
323
 
244
- * **`query`**: <`string`> A valid SQL query string. This overrides the query defined in the node properties.
245
- * **`payload`**:
246
- * A JSON string containing a `query` property with the SQL string.
247
- * An object with a `query` property containing the SQL string.
248
- * **`parameters`**: <`array` or `object`>
249
- * Can be an array of values corresponding to the placeholders (`?`) in the query.
250
- * Can be an object mapping parameter names to values. If the query contains placeholders (`?`) and `msg.parameters` is an object, the values will be automatically mapped to the placeholders based on the order of the parameters in the query.
324
+ - **`query`**: <`string`> A valid SQL query string. This overrides the query defined in the node properties.
325
+ - **`payload`**:
326
+ - A JSON string containing a `query` property with the SQL string.
327
+ - An object with a `query` property containing the SQL string.
328
+ - **`parameters`**: <`array` or `object`>
329
+ - Can be an array of values corresponding to the placeholders (`?`) in the query.
330
+ - Can be an object mapping parameter names to values. If the query contains placeholders (`?`) and `msg.parameters` is an object, the values will be automatically mapped to the placeholders based on the order of the parameters in the query.
251
331
 
252
332
  ## Outputs
253
333
 
254
334
  Returns a message containing:
255
335
 
256
- * **`output object`**: <`array`> The `odbc` result array returned from the query.
257
- * **`odbc`**: <`object`> Contains additional information returned by the `odbc` module.
258
- * **`parsedQuery`**: <`object`> (Optional) The parsed SQL query if the syntax checker is enabled.
336
+ - **`output object`**: <`array`> The `odbc` result array returned from the query.
337
+ - **`odbc`**: <`object`> Contains additional information returned by the `odbc` module.
338
+ - **`parsedQuery`**: <`object`> (Optional) The parsed SQL query if the syntax checker is enabled.
259
339
 
260
340
  ## Automatic Prepared Statement Handling
261
341
 
262
342
  The node automatically determines whether to use a prepared statement or a regular query based on the following:
263
343
 
264
- * **Presence of Placeholders:** If the query string contains placeholders (`?`), the node will use a prepared statement.
265
- * **`msg.parameters` Object/Array:** If the `msg.parameters` object/array is provided, the node will use a prepared statement.
344
+ - **Presence of Placeholders:** If the query string contains placeholders (`?`), the node will use a prepared statement.
345
+ - **`msg.parameters` Object/Array:** If the `msg.parameters` object/array is provided, the node will use a prepared statement.
266
346
 
267
347
  This automatic handling ensures that your queries are executed in the most secure way possible, minimizing the risk of SQL injection vulnerabilities.
268
- </script>
348
+ </script>