@bkmj/node-red-contrib-odbcmj 1.6.6 → 2.0.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 +63 -107
  2. package/odbc.html +224 -222
  3. package/odbc.js +380 -228
  4. package/package.json +26 -7
package/odbc.html CHANGED
@@ -1,268 +1,270 @@
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
+ credentials: {
5
+ // Le mot de passe est défini comme un "credential" sécurisé
6
+ password: { type: "password" }
7
+ },
4
8
  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}
9
+ name: { value: "" },
10
+ // Nouveaux champs pour le mode de connexion hybride
11
+ connectionMode: { value: "structured" },
12
+ dbType: { value: "sqlserver" },
13
+ driver: { value: "" },
14
+ server: { value: "" },
15
+ database: { value: "" },
16
+ user: { value: "" },
17
+ connectionString: { value: "" },
18
+ // Champs de pool et timeout
19
+ initialSize: { value: 5 },
20
+ incrementSize: { value: 5 },
21
+ maxSize: { value: 15 },
22
+ shrink: { value: true },
23
+ connectionTimeout: { value: 3 },
24
+ loginTimeout: { value: 3 },
25
+ // Champs de retry
26
+ retryFreshConnection: { value: false },
27
+ retryDelay: { value: 5, validate: RED.validators.number() },
28
+ retryOnMsg: { value: true },
29
+ // Champs avancés
30
+ syntaxtick: { value: false },
31
+ syntax: { value: "mysql" },
15
32
  },
16
- label: function() {
17
- return this.name || 'odbc config';
33
+ label: function () {
34
+ return this.name || "odbc config";
18
35
  },
19
- oneditprepare: function() {
20
- $(".input-syntax").hide();
21
- $("#node-config-input-syntaxtick").change(function() {
22
- if (this.checked){
23
- $(".input-syntax").show();
36
+ oneditprepare: function () {
37
+ var node = this;
38
+
39
+ // Logique pour afficher les bons champs selon le mode de connexion
40
+ function toggleConnectionMode(mode) {
41
+ if (mode === 'structured') {
42
+ $(".config-mode-structured").show();
43
+ $(".config-mode-string").hide();
44
+ } else {
45
+ $(".config-mode-structured").hide();
46
+ $(".config-mode-string").show();
47
+ }
48
+ }
49
+ // Gérer le changement du type de BD pour afficher/cacher le champ driver
50
+ function toggleDriverField(dbType) {
51
+ if (dbType === 'other') {
52
+ $("#node-config-driver-row").show();
24
53
  } else {
25
- $(".input-syntax").hide();
54
+ $("#node-config-driver-row").hide();
26
55
  }
56
+ }
57
+
58
+ // Initialisation de l'UI
59
+ $("#node-config-input-connectionMode").on("change", function() {
60
+ toggleConnectionMode($(this).val());
61
+ }).trigger("change");
62
+
63
+ $("#node-config-input-dbType").on("change", function() {
64
+ toggleDriverField($(this).val());
65
+ }).trigger("change");
66
+
67
+
68
+ // Logique pour le 'Syntax Checker'
69
+ $("#node-config-input-syntaxtick").on("change", function () {
70
+ $(".input-syntax").toggle(this.checked);
71
+ }).trigger("change");
72
+
73
+
74
+ // Logique pour afficher/masquer les options de retry
75
+ $("#node-config-input-retryFreshConnection").on("change", function() {
76
+ $(".retry-options").toggle(this.checked);
77
+ }).trigger("change");
78
+
79
+
80
+ // Logique pour le bouton de test de connexion
81
+ $('#node-config-test-connection').on('click', function() {
82
+ var button = $(this);
83
+ var originalText = button.text();
84
+ var icon = button.find("i");
85
+ icon.removeClass('fa-bolt').addClass('fa-spinner fa-spin');
86
+ button.text(' Testing...').prop('disabled', true);
87
+
88
+ // Collecter toutes les données du formulaire
89
+ var configData = {
90
+ connectionMode: $("#node-config-input-connectionMode").val(),
91
+ dbType: $("#node-config-input-dbType").val(),
92
+ driver: $("#node-config-input-driver").val(),
93
+ server: $("#node-config-input-server").val(),
94
+ database: $("#node-config-input-database").val(),
95
+ user: $("#node-config-input-user").val(),
96
+ password: $("#node-config-input-password").val(),
97
+ connectionString: $("#node-config-input-connectionString").val()
98
+ };
99
+
100
+ $.ajax({
101
+ url: "odbc_config/" + node.id + "/test",
102
+ type: "POST",
103
+ contentType: "application/json",
104
+ data: JSON.stringify(configData),
105
+ success: function(result) {
106
+ RED.notify("Connection successful!", {type:"success", timeout: 2000});
107
+ },
108
+ error: function(xhr, status, error) {
109
+ var errMsg = xhr.responseText || "Connection failed. Check Node-RED logs for details.";
110
+ RED.notify("Connection failed: " + errMsg, {type:"error", timeout: 4000});
111
+ },
112
+ complete: function() {
113
+ button.text(originalText).prop('disabled', false);
114
+ icon.removeClass('fa-spinner fa-spin').addClass('fa-bolt');
115
+ }
116
+ });
27
117
  });
28
- }
118
+ },
29
119
  });
30
120
  </script>
31
121
 
32
122
  <script type="text/html" data-template-name="odbc config">
33
-
34
123
  <div class="form-row">
35
124
  <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
36
- <input type="text" id="node-config-input-name">
125
+ <input type="text" id="node-config-input-name" placeholder="My DB Connection">
37
126
  </div>
38
127
 
39
128
  <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=...;">
42
- </div>
43
-
44
- <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">
47
- </div>
48
-
49
- <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">
52
- </div>
53
-
54
- <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">
57
- </div>
58
-
59
- <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;">
129
+ <label for="node-config-input-connectionMode"><i class="fa fa-cogs"></i> Mode</label>
130
+ <select id="node-config-input-connectionMode">
131
+ <option value="structured">Structured Fields (Recommended)</option>
132
+ <option value="string">Connection String (Advanced)</option>
133
+ </select>
62
134
  </div>
63
135
 
64
- <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">
136
+ <div class="config-mode-structured">
137
+ <div class="form-row">
138
+ <label for="node-config-input-dbType"><i class="fa fa-database"></i> Database Type</label>
139
+ <select id="node-config-input-dbType">
140
+ <option value="sqlserver">SQL Server</option>
141
+ <option value="postgresql">PostgreSQL</option>
142
+ <option value="mysql">MySQL</option>
143
+ <option value="other">Other (Specify Driver)</option>
144
+ </select>
145
+ </div>
146
+ <div class="form-row" id="node-config-driver-row">
147
+ <label for="node-config-input-driver"><i class="fa fa-info-circle"></i> Driver</label>
148
+ <input type="text" id="node-config-input-driver" placeholder="e.g., IBM i Access ODBC Driver">
149
+ </div>
150
+ <div class="form-row">
151
+ <label for="node-config-input-server"><i class="fa fa-server"></i> Server</label>
152
+ <input type="text" id="node-config-input-server" placeholder="hostname_or_ip,port">
153
+ </div>
154
+ <div class="form-row">
155
+ <label for="node-config-input-database"><i class="fa fa-table"></i> Database</label>
156
+ <input type="text" id="node-config-input-database" placeholder="(optional)">
157
+ </div>
158
+ <div class="form-row">
159
+ <label for="node-config-input-user"><i class="fa fa-user"></i> User</label>
160
+ <input type="text" id="node-config-input-user">
161
+ </div>
162
+ <div class="form-row">
163
+ <label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
164
+ <input type="password" id="node-config-input-password">
165
+ </div>
67
166
  </div>
68
-
69
- <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">
167
+
168
+ <div class="config-mode-string">
169
+ <div class="form-row">
170
+ <label for="node-config-input-connectionString"><i class="fa fa-font"></i> Connection String</label>
171
+ <input type="text" id="node-config-input-connectionString" placeholder="DRIVER={...};SERVER=...;PWD={{{password}}};">
172
+ </div>
173
+ <div class="form-row">
174
+ <label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
175
+ <input type="password" id="node-config-input-password">
176
+ <span class="form-tips">Use <code>{{{password}}}</code> placeholder in the string above.</span>
177
+ </div>
72
178
  </div>
73
179
 
74
180
  <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;">
181
+ <label>&nbsp;</label>
182
+ <button class="ui-button" id="node-config-test-connection" style="width: auto;"><i class="fa fa-bolt"></i> Test Connection</button>
77
183
  </div>
78
184
 
79
- <div class="form-row input-syntax">
80
- <label for=""><i class="icon-bookmark"></i> Syntax</label>
81
- <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>
91
- </select>
92
- </div>
93
- </script>
185
+ <hr/>
186
+ <h4><i class="fa fa-sitemap"></i> Pool Options</h4>
187
+ <hr/>
188
+ <h4><i class="fa fa-exclamation-triangle"></i> Error Handling & Retry</h4>
189
+ <hr/>
190
+ <h4><i class="fa fa-wrench"></i> Advanced</h4>
191
+ </script>
94
192
 
95
193
  <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
- });
194
+ RED.nodes.registerType("odbc", {
195
+ category: "storage-input",
196
+ color: "#89A5C0",
197
+ defaults: {
198
+ name: { value: "" },
199
+ connection: { type: "odbc config", required: true },
200
+ query: { value: "" },
201
+ outputObj: { value: "payload" },
202
+ // Nouveaux champs pour le streaming
203
+ streaming: { value: false },
204
+ streamChunkSize: { value: 1, validate: RED.validators.number() }
205
+ },
206
+ inputs: 1,
207
+ outputs: 1,
208
+ icon: "db.svg",
209
+ label: function () {
210
+ return this.name || "odbc";
211
+ },
212
+ oneditprepare: function () {
213
+ this.editor = RED.editor.createEditor({
214
+ id: "node-input-query-editor",
215
+ mode: "ace/mode/sql",
216
+ value: this.query,
217
+ });
218
+
219
+ // Logique pour afficher/cacher le champ de taille de lot
220
+ $("#node-input-streaming").on("change", function() {
221
+ $(".stream-options").toggle(this.checked);
222
+ }).trigger("change");
223
+ },
224
+ oneditsave: function () {
225
+ this.query = this.editor.getValue();
226
+ this.editor.destroy();
227
+ delete this.editor;
228
+ },
229
+ oneditcancel: function () {
230
+ this.editor.destroy();
231
+ delete this.editor;
232
+ },
233
+ });
128
234
  </script>
129
235
 
130
236
  <script type="text/html" data-template-name="odbc">
131
-
132
237
  <div class="form-row">
133
238
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
134
- <input type="text" id="node-input-name">
239
+ <input type="text" id="node-input-name" />
135
240
  </div>
136
241
 
137
242
  <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">
243
+ <label for="node-input-connection"><i class="fa fa-cog"></i> Connection</label>
244
+ <input type="text" id="node-input-connection" />
140
245
  </div>
141
246
 
142
247
  <div class="form-row node-text-editor-row">
143
248
  <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>
249
+ <div style="height: 250px;" class="node-text-editor" id="node-input-query-editor"></div>
145
250
  </div>
146
251
 
147
252
  <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%;">
253
+ <label for="node-input-outputObj"><i class="fa fa-edit"></i> Result to</label>
254
+ <span>msg.</span><input type="text" id="node-input-outputObj" placeholder="payload" style="width: 64%;"/>
150
255
  </div>
151
- </script>
152
- <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.
156
-
157
- ## Properties
158
-
159
- * (**required**) **`connectionString`**: <`string`>
160
-
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.
163
-
164
- Example:
165
- ```
166
- DSN=MyDSN;DFT=2;
167
- ```
168
256
 
169
- * (optional) **`initialSize`**: <`number`>
257
+ <hr/>
258
+ <h4><i class="fa fa-sliders"></i> Advanced Options</h4>
170
259
 
171
- The number of connections created in the pool when it is initialized. Default: 5.
172
-
173
- * (optional) **`incrementSize`**: <`number`>
174
-
175
- The number of connections that are created when the pool is exhausted. Default: 5.
176
-
177
- * (optional) **`maxSize`**: <`number`>
178
-
179
- The maximum number of connections allowed in the pool before it won't create any more. Default: 15.
180
-
181
- * (optional) **`shrinkPool`**: <`boolean`>
182
-
183
- Whether the number of connections should be reduced to `initialSize` when they are returned to the pool. Default: true.
184
-
185
- * (optional) **`connectionTimeout`**: <`number`>
186
-
187
- The number of seconds for a connection to remain idle before closing. Default: 3.
188
-
189
- * (optional) **`loginTimeout`**: <`number`>
190
-
191
- The number of seconds for an attempt to create a connection before returning to the application. Default: 3.
192
-
193
- * (optional) **`syntaxChecker`**: <`boolean`>
194
-
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.
198
-
199
- * (optional) **`syntax`**: <`string`>
200
-
201
- Dropdown list of the available [SQL flavors available](https://www.npmjs.com/package/node-sql-parser#supported-database-sql-syntax).
202
- Default: mysql.
203
- </script>
204
-
205
- <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
208
- defined in the node properties.
209
-
210
- ## Properties
211
-
212
- * (**required**) **`connection`**: <`odbc config`>
213
-
214
- The ODBC pool node that defines the connection settings and manages the connection pool used by this node.
215
-
216
- * (optional) **`query`**: <`string`>
217
-
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.
222
-
223
- * (**required**) **`result to`**: <`dot-notation string`>
224
-
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
230
- was itself an object (but not an array); otherwise, the original key/value pair will be overwritten.
231
-
232
- Example:
233
-
234
- * `input msg: {"payload": {"result": {"othervalue": 10} } };`
235
- * `result to: payload.results.values`
236
-
237
- In this case, `values` will be appended to `result` without overwriting `othervalue`.
238
- If `result` had been a string, then it would have been replaced by `values`.
239
-
240
- ## Inputs
241
-
242
- The `odbc` node accepts a message input that can contain:
243
-
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.
251
-
252
- ## Outputs
253
-
254
- Returns a message containing:
255
-
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.
259
-
260
- ## Automatic Prepared Statement Handling
261
-
262
- The node automatically determines whether to use a prepared statement or a regular query based on the following:
263
-
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.
260
+ <div class="form-row">
261
+ <label for="node-input-streaming" style="width: auto;"><i class="fa fa-arrows-v"></i> Stream Results</label>
262
+ <input type="checkbox" id="node-input-streaming" style="display: inline-block; width: auto; vertical-align: top;">
263
+ </div>
266
264
 
267
- This automatic handling ensures that your queries are executed in the most secure way possible, minimizing the risk of SQL injection vulnerabilities.
265
+ <div class="form-row stream-options">
266
+ <label for="node-input-streamChunkSize"><i class="fa fa-bars"></i> Chunk Size</label>
267
+ <input type="number" id="node-input-streamChunkSize" placeholder="1" style="width: 100px;">
268
+ <span class="form-tips">Number of rows per output message.</span>
269
+ </div>
268
270
  </script>