@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.
Files changed (4) hide show
  1. package/README.md +79 -28
  2. package/odbc.html +261 -260
  3. package/odbc.js +259 -536
  4. 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 connections in an `odbc.pool` object. [Can take any configuration property recognized by `odbc.pool()`](https://www.npmjs.com/package/odbc#constructor-odbcpoolconnectionstring). The connection pool will initialize the first time
4
- an `odbc` node receives an input message.
23
+ A configuration node that manages the connection to your database.
5
24
 
6
- #### Properties
25
+ #### Connection Modes
7
26
 
8
- - (**required**) **`connectionString`**: <`string`>
27
+ Version 2.0 introduces two ways to configure your connection:
9
28
 
10
- An ODBC connection string that defines your DSN and/or connection string options.
11
- Check your ODBC driver documentation for more information about valid connection strings.
29
+ ##### 1. Structured Fields Mode (Recommended)
12
30
 
13
- Example:
31
+ This is the easiest and most secure way to set up a connection for common databases.
14
32
 
15
- ```
16
- DSN=MyDSN;DFT=2;
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
- - (optional) **`initialSize`**: <`number`>
39
+ ##### 2. Connection String Mode (Advanced)
20
40
 
21
- The number of connections created in the pool when it is initialized. Default: 5.
41
+ This mode gives you full control for complex or non-standard connection strings.
22
42
 
23
- - (optional) **`incrementSize`**: <`number`>
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
- The number of connections that are created when the pool is exhausted. Default: 5.
47
+ #### Test Connection
26
48
 
27
- - (optional) **`maxSize`**: <`number`>
49
+ A **Test Connection** button in the configuration panel allows you to instantly verify your settings without deploying the flow.
28
50
 
29
- The maximum number of connections allowed in the pool before it won't create any more. Default: 15.
51
+ #### Pool Options
30
52
 
31
- - (optional) **`shrinkPool`**: <`boolean`>
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
- Whether the number of connections should be reduced to `initialSize` when they are returned to the pool. Default: true.
60
+ #### Error Handling & Retry
34
61
 
35
- - (optional) **`connectionTimeout`**: <`number`>
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
- The number of seconds for a connection to remain idle before closing. Default: 3.
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
- - (optional) **`loginTimeout`**: <`number`>
83
+ #### Inputs
40
84
 
41
- The number of seconds for an attempt to create a connection before returning to the application.
42
- Default: 3.
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
- - (optional) **`retryFreshConnection`**: <`boolean`> If checked, in case of a query error when using a pooled connection, the node will attempt the query a second time using a brand new database connection (not from the pool). If this second attempt is successful, it indicates the original pooled connection or the pool itself might be problematic. Consequently, the entire connection pool will be closed and reset, forcing a new pool to be created on subsequent requests. This can help recover from stale or broken connections within the pool. Default: false.
89
+ #### Streaming Results
45
90
 
46
- - (optional) **`syntaxChecker`**: <`boolean`>
91
+ For queries that return a large number of rows, streaming prevents high memory usage.
47
92
 
48
- Whether the syntax validator is activated or not. 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 with a key named `parsedSql`. Default: false.
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
- - (optional) **`syntax`**: <`string`>
96
+ ##### Streaming Output Format
51
97
 
52
- Dropdown list of the available [SQL flavors available](https://www.npmjs.com/package/node-sql-parser#supported-database-sql-syntax). Default: mysql.
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.