@bkmj/node-red-contrib-odbcmj 1.7.0 → 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.
- package/README.md +79 -28
- package/odbc.html +261 -260
- 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.
|