-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmysql-r2.html
174 lines (153 loc) · 6.47 KB
/
mysql-r2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<script type="text/javascript">
RED.nodes.registerType('mysql-r2', {
category: 'database',
color: '#F3B567',
defaults: {
name: { value: '' },
host: { value: 'localhost' },
database: { value: '' },
username: { value: '' },
password: { value: '' },
sql: { value: '' },
port: { value: 3306 }, // Add a default value for the port
pooling: { value: false },
waitForConnections: { value: true },
connectionLimit: { value: 10 },
queueTimeout: { value: 10000 },
},
inputs: 1,
outputs: 1,
icon: 'font-awesome/fa-database',
label: function () {
return this.name || 'mysql-r2';
},
oneditprepare: function () {
$("#node-input-pooling").on("change", function () {
const poolingChecked = $(this).prop("checked");
$("#node-input-waitForConnections, #node-input-connectionLimit, #node-input-queueTimeout").prop("disabled", !poolingChecked);
}).trigger("change");
const inputs = [
"name",
"host",
"database",
"username",
"password",
"sql",
"port", // Add "port" to the inputs array
"pooling",
"waitForConnections",
"connectionLimit",
"queueTimeout",
];
inputs.forEach((input) => {
const inputElement = $(`#node-input-${input}`);
const inputValue = this[input];
if (inputElement.is(":checkbox")) {
inputElement.prop("checked", inputValue);
} else {
inputElement.val(inputValue);
}
inputElement.on("change", () => {
this[input] = inputElement.is(":checkbox") ? inputElement.prop("checked") : inputElement.val();
});
});
},
});
</script>
<script type="text/html" data-template-name="mysql-r2">
<div class="form-row">
<label for="node-input-name">
<i class="fa fa-tag"></i> Name
</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-host">
<i class="fa fa-server"></i> Host
</label>
<input type="text" id="node-input-host" placeholder="Host/msg.host">
</div>
<div class="form-row">
<label for="node-input-port">
<i class="fa fa-plug"></i> Port
</label>
<input type="number" id="node-input-port" placeholder="Port/msg.port" min="1" step="1">
</div>
<div class="form-row">
<label for="node-input-database">
<i class="fa fa-database"></i> Database
</label>
<input type="text" id="node-input-database" placeholder="Database/msg.database">
</div>
<div class="form-row">
<label for="node-input-username">
<i class="fa fa-user"></i> Username
</label>
<input type="text" id="node-input-username" placeholder="Username/msg.username">
</div>
<div class="form-row">
<label for="node-input-password">
<i class="fa fa-lock"></i> Password
</label>
<input type="password" id="node-input-password" placeholder="Password/msg.password">
</div>
<div class="form-row">
<label for="node-input-sql">
<i class="fa fa-code"></i> SQL
</label>
<textarea id="node-input-sql" rows="4" placeholder="SQL/msg.sql"></textarea>
</div>
<hr>
<div class="form-row">
<label for="node-input-pooling">
<i class="fa fa-cogs"></i> Connection Pooling
</label>
<input type="checkbox" id="node-input-pooling">
</div>
<div class="form-row">
<label for="node-input-waitForConnections">
<i class="fa fa-clock-o"></i> Wait for Connections
</label>
<input type="checkbox" id="node-input-waitForConnections">
</div>
<div class="form-row">
<label for="node-input-connectionLimit">
<i class="fa fa-chain"></i> Connection Limit
</label>
<input type="number" id="node-input-connectionLimit" min="1" step="1">
</div>
<div class="form-row">
<label for="node-input-queueTimeout">
<i class="fa fa-hourglass-end"></i> Queue Timeout (ms)
</label>
<input type="number" id="node-input-queueTimeout" min="1" step="1">
</div>
</script>
<script type="text/markdown" data-help-name="mysql-r2">
This Node-RED node allows you to execute MySQL queries against a specified database table.
### Configuration
The `mysql-r2` node can be configured using the following properties.
* Name: A user-friendly name for the node.
* Host: The host of the MySQL server to connect to.
* Port: The port number of the MySQL server to connect to. If not set, the default MySQL port (3306) will be used.
* Database: The name of the MySQL database to connect to.
* Username: The username to use to authenticate with the MySQL database.
* Password: The password to use to authenticate with the MySQL database.
* SQL: The SQL query to execute against the specified table.
* Connection Pooling: Enable or disable connection pooling.
* Wait for Connections: Determines whether the pool should wait for a connection to be available when there are no more available connections.
* Connection Limit: The maximum number of connections to create at once.
* Queue Timeout: The maximum number of milliseconds to wait before timing out when waiting for a connection to become available.
### Inputs
The `mysql-r2` node accepts a message with the following properties.
: msg.sql (string) : The SQL query to execute against the specified table. If not set, the query defined in the node configuration will be used.
: msg.host (string) : The host of the MySQL server to connect to. If not set, the host defined in the node configuration will be used.
: msg.port (number) : The port number of the MySQL server to connect to. If not set, the port defined in the node configuration will be used.
: msg.database (string) : The name of the MySQL database to connect to. If not set, the database name defined in the node configuration will be used.
: msg.username (string) : The username to use to authenticate with the MySQL database. If not set, the username defined in the node configuration will be used.
: msg.password (string) : The password to use to authenticate with the MySQL database. If not set, the password defined in the node configuration will be used.
### Outputs
The `mysql-r2` node outputs a message with the following properties.
1. Standard output
: msg.payload (string) : The results of the SQL query as an array of objects. Each object in the array represents a row in the query results, with property names corresponding to the column names in the result set.
</script>