@bkmj/node-red-contrib-odbcmj 1.7.0 → 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.
- package/README.md +79 -28
- package/odbc.html +181 -259
- package/odbc.js +259 -536
- package/package.json +26 -7
package/README.md
CHANGED
|
@@ -1,52 +1,103 @@
|
|
|
1
|
+
# Node-RED Contrib ODBC MJ
|
|
2
|
+
|
|
3
|
+
A powerful and robust Node-RED node to connect to any ODBC data source. It features connection pooling, advanced retry logic, secure credential management, and result set streaming.
|
|
4
|
+
|
|
5
|
+
This node is a fork with significant enhancements to provide stability and advanced features for enterprise use cases.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Connection Pooling**: Efficiently manages database connections for high performance.
|
|
10
|
+
- **Hybrid Configuration**: Configure connections using simple structured fields or a full connection string for maximum flexibility.
|
|
11
|
+
- **Secure Credential Storage**: Passwords are saved using Node-RED's built-in credential system.
|
|
12
|
+
- **Connection Tester**: Instantly validate your connection settings from the configuration panel.
|
|
13
|
+
- **Advanced Retry Logic**: Automatically handles connection errors with configurable delays and retries to ensure flow resilience.
|
|
14
|
+
- **Result Streaming**: Process queries with millions of rows without exhausting memory by streaming results as chunks.
|
|
15
|
+
- **Syntax Checker**: Optionally parse the SQL query to validate its structure.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Nodes
|
|
20
|
+
|
|
1
21
|
### `odbc config`
|
|
2
22
|
|
|
3
|
-
A configuration node that manages
|
|
4
|
-
an `odbc` node receives an input message.
|
|
23
|
+
A configuration node that manages the connection to your database.
|
|
5
24
|
|
|
6
|
-
####
|
|
25
|
+
#### Connection Modes
|
|
7
26
|
|
|
8
|
-
|
|
27
|
+
Version 2.0 introduces two ways to configure your connection:
|
|
9
28
|
|
|
10
|
-
|
|
11
|
-
Check your ODBC driver documentation for more information about valid connection strings.
|
|
29
|
+
##### 1. Structured Fields Mode (Recommended)
|
|
12
30
|
|
|
13
|
-
|
|
31
|
+
This is the easiest and most secure way to set up a connection for common databases.
|
|
14
32
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
33
|
+
- **Database Type**: Select your database (e.g., SQL Server, PostgreSQL, MySQL). The node will use the appropriate driver name and connection string syntax. For unlisted databases, choose "Other" and provide the driver name manually.
|
|
34
|
+
- **Server**: The hostname or IP address of the database server, optionally followed by a comma and the port number (e.g., `mydb.server.com,1433`).
|
|
35
|
+
- **Database**: The name of the database to connect to (optional).
|
|
36
|
+
- **User**: The username for authentication.
|
|
37
|
+
- **Password**: The password for authentication. This is stored securely using Node-RED's credential system.
|
|
18
38
|
|
|
19
|
-
|
|
39
|
+
##### 2. Connection String Mode (Advanced)
|
|
20
40
|
|
|
21
|
-
|
|
41
|
+
This mode gives you full control for complex or non-standard connection strings.
|
|
22
42
|
|
|
23
|
-
-
|
|
43
|
+
- **Connection String**: Enter the complete ODBC connection string.
|
|
44
|
+
- **Password Handling**: For security, **do not** write your password directly in the string. Instead, use the `{{{password}}}` placeholder. The node will automatically replace it with the password entered in the secure `Password` field below.
|
|
45
|
+
- Example: `DRIVER={...};SERVER=...;UID=myuser;PWD={{{password}}};`
|
|
24
46
|
|
|
25
|
-
|
|
47
|
+
#### Test Connection
|
|
26
48
|
|
|
27
|
-
|
|
49
|
+
A **Test Connection** button in the configuration panel allows you to instantly verify your settings without deploying the flow.
|
|
28
50
|
|
|
29
|
-
|
|
51
|
+
#### Pool Options
|
|
30
52
|
|
|
31
|
-
- (optional)
|
|
53
|
+
- **`initialSize`** `<number>` (optional): The number of connections to create when the pool is initialized. Default: 5.
|
|
54
|
+
- **`incrementSize`** `<number>` (optional): The number of connections to create when the pool is exhausted. Default: 5.
|
|
55
|
+
- **`maxSize`** `<number>` (optional): The maximum number of connections allowed in the pool. Default: 15.
|
|
56
|
+
- **`shrinkPool`** `<boolean>` (optional): Whether to reduce the number of connections to `initialSize` when they are returned to the pool. Default: true.
|
|
57
|
+
- **`connectionTimeout`** `<number>` (optional): The number of seconds for a connection to remain idle before closing. Default: 3.
|
|
58
|
+
- **`loginTimeout`** `<number>` (optional): The number of seconds for an attempt to create a connection to succeed. Default: 3.
|
|
32
59
|
|
|
33
|
-
|
|
60
|
+
#### Error Handling & Retry
|
|
34
61
|
|
|
35
|
-
- (optional)
|
|
62
|
+
- **`retryFreshConnection`** `<boolean>` (optional): If a query fails, the node will retry once with a brand new connection. If this succeeds, the entire connection pool is reset to clear any stale connections. Default: false.
|
|
63
|
+
- **`retryDelay`** `<number>` (optional): If both the pooled and the fresh connection attempts fail, this sets a delay in seconds before another retry is attempted. This prevents infinite loops. A value of **0** disables further automatic retries. Default: 5.
|
|
64
|
+
- **`retryOnMsg`** `<boolean>` (optional): If the node is waiting for a timed retry, a new incoming message can override the timer and trigger an immediate retry. Default: true.
|
|
65
|
+
|
|
66
|
+
#### Advanced
|
|
67
|
+
|
|
68
|
+
- **`syntaxChecker`** `<boolean>` (optional): If activated, the query string will be [parsed](https://www.npmjs.com/package/node-sql-parser#create-ast-for-sql-statement) and appended as an object to the output message at `msg.parsedQuery`. Default: false.
|
|
69
|
+
- **`syntax`** `<string>` (optional): The SQL flavor to use for the syntax checker. Default: mysql.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### `odbc`
|
|
74
|
+
|
|
75
|
+
This node executes a query against the configured database when it receives a message.
|
|
76
|
+
|
|
77
|
+
#### Properties
|
|
36
78
|
|
|
37
|
-
|
|
79
|
+
- **`connection`** `<odbc config>` (**required**): The configuration node that defines the connection settings.
|
|
80
|
+
- **`query`** `<string>` (optional): The SQL query to execute. Can contain Mustache syntax (e.g., `{{{payload.id}}}`) which will be rendered using the incoming message object.
|
|
81
|
+
- **`result to`** `<string>` (**required**): The property of the output message where the results will be stored (e.g., `payload`). Default: `payload`.
|
|
38
82
|
|
|
39
|
-
|
|
83
|
+
#### Inputs
|
|
40
84
|
|
|
41
|
-
|
|
42
|
-
|
|
85
|
+
The node can be configured dynamically using the incoming `msg` object:
|
|
86
|
+
- **`msg.query`**: A query string that will override the one configured in the node.
|
|
87
|
+
- **`msg.parameters`**: An array of values for prepared statements (when the query contains `?` placeholders).
|
|
43
88
|
|
|
44
|
-
|
|
89
|
+
#### Streaming Results
|
|
45
90
|
|
|
46
|
-
|
|
91
|
+
For queries that return a large number of rows, streaming prevents high memory usage.
|
|
47
92
|
|
|
48
|
-
|
|
93
|
+
- **`Stream Results`** `<boolean>`: Enables or disables streaming mode. When enabled, the node will output multiple messages, one for each chunk of rows. Default: false.
|
|
94
|
+
- **`Chunk Size`** `<number>`: The number of rows to include in each output message. A value of `1` means one message will be sent for every single row. Default: 1.
|
|
49
95
|
|
|
50
|
-
|
|
96
|
+
##### Streaming Output Format
|
|
51
97
|
|
|
52
|
-
|
|
98
|
+
When streaming is active, each output message will contain:
|
|
99
|
+
- A payload (or the configured output property) containing an array of rows for the current chunk.
|
|
100
|
+
- A `msg.odbc_stream` object with metadata for tracking progress:
|
|
101
|
+
- `index`: The starting index of the current chunk (e.g., 0, 100, 200...).
|
|
102
|
+
- `count`: The number of rows in the current chunk.
|
|
103
|
+
- `complete`: A boolean that is `true` only on the very last message of the stream (or if the result set was empty), and `false` otherwise. This is useful for triggering a downstream action once all rows have been processed.
|
package/odbc.html
CHANGED
|
@@ -1,31 +1,119 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
2
|
RED.nodes.registerType("odbc config", {
|
|
3
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
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
|
|
7
19
|
initialSize: { value: 5 },
|
|
8
20
|
incrementSize: { value: 5 },
|
|
9
21
|
maxSize: { value: 15 },
|
|
10
22
|
shrink: { value: true },
|
|
11
|
-
syntaxtick: { value: false },
|
|
12
|
-
syntax: { value: "mysql" },
|
|
13
23
|
connectionTimeout: { value: 3 },
|
|
14
24
|
loginTimeout: { value: 3 },
|
|
15
|
-
//
|
|
16
|
-
retryFreshConnection: { value: false },
|
|
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" },
|
|
17
32
|
},
|
|
18
33
|
label: function () {
|
|
19
34
|
return this.name || "odbc config";
|
|
20
35
|
},
|
|
21
36
|
oneditprepare: function () {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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();
|
|
26
53
|
} else {
|
|
27
|
-
$("
|
|
54
|
+
$("#node-config-driver-row").hide();
|
|
28
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
|
+
});
|
|
29
117
|
});
|
|
30
118
|
},
|
|
31
119
|
});
|
|
@@ -33,135 +121,87 @@
|
|
|
33
121
|
|
|
34
122
|
<script type="text/html" data-template-name="odbc config">
|
|
35
123
|
<div class="form-row">
|
|
36
|
-
<label for="node-config-input-name"
|
|
37
|
-
|
|
38
|
-
>
|
|
39
|
-
<input type="text" id="node-config-input-name" />
|
|
40
|
-
</div>
|
|
41
|
-
|
|
42
|
-
<div class="form-row">
|
|
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
|
-
/>
|
|
51
|
-
</div>
|
|
52
|
-
|
|
53
|
-
<div class="form-row">
|
|
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
|
-
/>
|
|
62
|
-
</div>
|
|
63
|
-
|
|
64
|
-
<div class="form-row">
|
|
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
|
-
/>
|
|
73
|
-
</div>
|
|
74
|
-
|
|
75
|
-
<div class="form-row">
|
|
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" />
|
|
124
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
125
|
+
<input type="text" id="node-config-input-name" placeholder="My DB Connection">
|
|
80
126
|
</div>
|
|
81
127
|
|
|
82
128
|
<div class="form-row">
|
|
83
|
-
<label for="node-config-input-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
id="node-config-input-shrink"
|
|
89
|
-
style="margin-left:0px; vertical-align:top; width:auto !important;"
|
|
90
|
-
/>
|
|
91
|
-
</div>
|
|
92
|
-
|
|
93
|
-
<div class="form-row">
|
|
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
|
-
/>
|
|
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>
|
|
102
134
|
</div>
|
|
103
135
|
|
|
104
|
-
<div class="
|
|
105
|
-
<
|
|
106
|
-
><i class="fa fa-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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>
|
|
113
166
|
</div>
|
|
114
|
-
|
|
115
|
-
<div class="
|
|
116
|
-
<
|
|
117
|
-
><i class="fa fa-
|
|
118
|
-
|
|
119
|
-
>
|
|
120
|
-
<
|
|
121
|
-
|
|
122
|
-
id="node-config-input-
|
|
123
|
-
|
|
124
|
-
|
|
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>
|
|
125
178
|
</div>
|
|
126
179
|
|
|
127
180
|
<div class="form-row">
|
|
128
|
-
<label
|
|
129
|
-
|
|
130
|
-
>
|
|
131
|
-
<input
|
|
132
|
-
type="checkbox"
|
|
133
|
-
id="node-config-input-syntaxtick"
|
|
134
|
-
style="display: inline-block; width: auto; vertical-align: top;"
|
|
135
|
-
/>
|
|
181
|
+
<label> </label>
|
|
182
|
+
<button class="ui-button" id="node-config-test-connection" style="width: auto;"><i class="fa fa-bolt"></i> Test Connection</button>
|
|
136
183
|
</div>
|
|
137
184
|
|
|
138
|
-
<
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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>
|
|
152
|
-
</select>
|
|
153
|
-
</div>
|
|
154
|
-
</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>
|
|
155
192
|
|
|
156
193
|
<script type="text/javascript">
|
|
157
194
|
RED.nodes.registerType("odbc", {
|
|
158
|
-
category: "storage",
|
|
195
|
+
category: "storage-input",
|
|
159
196
|
color: "#89A5C0",
|
|
160
197
|
defaults: {
|
|
161
198
|
name: { value: "" },
|
|
162
199
|
connection: { type: "odbc config", required: true },
|
|
163
200
|
query: { value: "" },
|
|
164
201
|
outputObj: { value: "payload" },
|
|
202
|
+
// Nouveaux champs pour le streaming
|
|
203
|
+
streaming: { value: false },
|
|
204
|
+
streamChunkSize: { value: 1, validate: RED.validators.number() }
|
|
165
205
|
},
|
|
166
206
|
inputs: 1,
|
|
167
207
|
outputs: 1,
|
|
@@ -175,6 +215,11 @@
|
|
|
175
215
|
mode: "ace/mode/sql",
|
|
176
216
|
value: this.query,
|
|
177
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");
|
|
178
223
|
},
|
|
179
224
|
oneditsave: function () {
|
|
180
225
|
this.query = this.editor.getValue();
|
|
@@ -195,154 +240,31 @@
|
|
|
195
240
|
</div>
|
|
196
241
|
|
|
197
242
|
<div class="form-row">
|
|
198
|
-
<label for="node-input-connection"
|
|
199
|
-
><i class="fa fa-cog"></i> Connection</label
|
|
200
|
-
>
|
|
243
|
+
<label for="node-input-connection"><i class="fa fa-cog"></i> Connection</label>
|
|
201
244
|
<input type="text" id="node-input-connection" />
|
|
202
245
|
</div>
|
|
203
246
|
|
|
204
247
|
<div class="form-row node-text-editor-row">
|
|
205
|
-
<label for="node-input-query" style="width: 100% !important;"
|
|
206
|
-
|
|
207
|
-
>
|
|
208
|
-
<div
|
|
209
|
-
style="height: 250px;"
|
|
210
|
-
class="node-text-editor"
|
|
211
|
-
id="node-input-query-editor"
|
|
212
|
-
></div>
|
|
248
|
+
<label for="node-input-query" style="width: 100% !important;"><i class="fa fa-search"></i> Query</label>
|
|
249
|
+
<div style="height: 250px;" class="node-text-editor" id="node-input-query-editor"></div>
|
|
213
250
|
</div>
|
|
214
251
|
|
|
215
252
|
<div class="form-row">
|
|
216
|
-
<label for="node-input-outputObj"
|
|
217
|
-
|
|
218
|
-
>
|
|
219
|
-
<span>msg.</span
|
|
220
|
-
><input
|
|
221
|
-
type="text"
|
|
222
|
-
id="node-input-outputObj"
|
|
223
|
-
placeholder="payload"
|
|
224
|
-
style="width: 64%;"
|
|
225
|
-
/>
|
|
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%;"/>
|
|
226
255
|
</div>
|
|
227
|
-
</script>
|
|
228
|
-
<script type="text/markdown" data-help-name="odbc config">
|
|
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.
|
|
232
|
-
|
|
233
|
-
## Properties
|
|
234
|
-
|
|
235
|
-
- (**required**) **`connectionString`**: <`string`>
|
|
236
|
-
|
|
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.
|
|
239
|
-
|
|
240
|
-
Example:
|
|
241
|
-
|
|
242
|
-
```
|
|
243
|
-
DSN=MyDSN;DFT=2;
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
- (optional) **`initialSize`**: <`number`>
|
|
247
|
-
|
|
248
|
-
The number of connections created in the pool when it is initialized. Default: 5.
|
|
249
|
-
|
|
250
|
-
- (optional) **`incrementSize`**: <`number`>
|
|
251
256
|
|
|
252
|
-
|
|
257
|
+
<hr/>
|
|
258
|
+
<h4><i class="fa fa-sliders"></i> Advanced Options</h4>
|
|
253
259
|
|
|
254
|
-
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
- (optional) **`shrinkPool`**: <`boolean`>
|
|
259
|
-
|
|
260
|
-
Whether the number of connections should be reduced to `initialSize` when they are returned to the pool. Default: true.
|
|
261
|
-
|
|
262
|
-
- (optional) **`connectionTimeout`**: <`number`>
|
|
263
|
-
|
|
264
|
-
The number of seconds for a connection to remain idle before closing. Default: 3.
|
|
265
|
-
|
|
266
|
-
- (optional) **`loginTimeout`**: <`number`>
|
|
267
|
-
|
|
268
|
-
The number of seconds for an attempt to create a connection before returning to the application. Default: 3.
|
|
269
|
-
|
|
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.
|
|
271
|
-
|
|
272
|
-
- (optional) **`syntaxChecker`**: <`boolean`>
|
|
273
|
-
|
|
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.
|
|
282
|
-
</script>
|
|
283
|
-
|
|
284
|
-
<script type="text/markdown" data-help-name="odbc">
|
|
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
|
|
287
|
-
defined in the node properties.
|
|
288
|
-
|
|
289
|
-
## Properties
|
|
290
|
-
|
|
291
|
-
- (**required**) **`connection`**: <`odbc config`>
|
|
292
|
-
|
|
293
|
-
The ODBC pool node that defines the connection settings and manages the connection pool used by this node.
|
|
294
|
-
|
|
295
|
-
- (optional) **`query`**: <`string`>
|
|
296
|
-
|
|
297
|
-
A valid SQL query string.
|
|
298
|
-
|
|
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.
|
|
302
|
-
|
|
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
|
|
310
|
-
was itself an object (but not an array); otherwise, the original key/value pair will be overwritten.
|
|
311
|
-
|
|
312
|
-
Example:
|
|
313
|
-
|
|
314
|
-
- `input msg: {"payload": {"result": {"othervalue": 10} } };`
|
|
315
|
-
- `result to: payload.results.values`
|
|
316
|
-
|
|
317
|
-
In this case, `values` will be appended to `result` without overwriting `othervalue`.
|
|
318
|
-
If `result` had been a string, then it would have been replaced by `values`.
|
|
319
|
-
|
|
320
|
-
## Inputs
|
|
321
|
-
|
|
322
|
-
The `odbc` node accepts a message input that can contain:
|
|
323
|
-
|
|
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.
|
|
331
|
-
|
|
332
|
-
## Outputs
|
|
333
|
-
|
|
334
|
-
Returns a message containing:
|
|
335
|
-
|
|
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.
|
|
339
|
-
|
|
340
|
-
## Automatic Prepared Statement Handling
|
|
341
|
-
|
|
342
|
-
The node automatically determines whether to use a prepared statement or a regular query based on the following:
|
|
343
|
-
|
|
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.
|
|
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>
|
|
346
264
|
|
|
347
|
-
|
|
348
|
-
</
|
|
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>
|
|
270
|
+
</script>
|