Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-postgresql",
"version": "0.15.4",
"version": "0.15.5",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"version": "0.15.5",
"version": "0.16.0",

"description": "Node-RED node for PostgreSQL, supporting parameters, split, back-pressure",
"author": {
"name": "Alexandre Alapetite",
Expand Down
37 changes: 5 additions & 32 deletions postgresql.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@
<span data-i18n="postgresql.label.user"></span>
</label>
<input type="text" id="node-config-input-user" data-i18n="[placeholder]postgresql.placeholder.user" style="width: 80%;" />
<input type="hidden" id="node-config-input-userFieldType" />
</div>
<div class="form-row">
<label for="node-config-input-password">
<i class="fa fa-lock"></i>
<span data-i18n="postgresql.label.password"></span>
</label>
<input type="password" id="node-config-input-password" data-i18n="[placeholder]postgresql.placeholder.password" style="width: 80%;" />
<input type="hidden" id="node-config-input-passwordFieldType" />
</div>
</div>
<div id="postgresql-config-tab-pool" style="display: none;">
Expand Down Expand Up @@ -153,22 +151,13 @@
connectionTimeoutFieldType: {
value: 'num',
},
user: {
value: '',
},
userFieldType: {
value: 'str',
},
password: {
value: '',
},
passwordFieldType: {
// TODO: https://nodered.org/docs/creating-nodes/credentials
value: 'str',
},
},
credentials: {
user: { type: 'text' },
password: { type: 'password' },
},
label: function () {
return this.name || this.user + '@' + this.host + ':' + this.port + '/' + this.database;
return this.name || this.host + ':' + this.port + '/' + this.database;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn’t it be good to keep the user in this information?

},
labelStyle: function () {
return this.name ? 'node_label_italic' : '';
Expand Down Expand Up @@ -213,17 +202,6 @@
types: ['bool', 'global', 'env', 'json'],
typeField: $('#node-config-input-sslFieldType'),
});
$('#node-config-input-user').typedInput({
default: 'str',
types: ['str', 'global', 'env'],
typeField: $('#node-config-input-userFieldType'),
});
$('#node-config-input-password')
.typedInput({
default: 'str',
types: ['str', 'global', 'env'],
typeField: $('#node-config-input-passwordFieldType'),
});
$('#node-config-input-applicationName').typedInput({
default: 'str',
types: ['str', 'global', 'env'],
Expand All @@ -234,11 +212,6 @@
types: ['num', 'global'],
typeField: $('#node-config-input-maxFieldType'),
});
$('#node-config-input-lin').typedInput({
default: 'num',
types: ['num', 'global'],
typeField: $('#node-config-input-linFieldType'),
});
$('#node-config-input-idle').typedInput({
default: 'num',
types: ['num', 'global'],
Expand Down
17 changes: 10 additions & 7 deletions postgresql.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module.exports = function (RED) {
function PostgreSQLConfigNode(n) {
const node = this;
RED.nodes.createNode(node, n);

node.name = n.name;
node.host = n.host;
node.hostFieldType = n.hostFieldType;
Expand All @@ -69,16 +70,12 @@ module.exports = function (RED) {
node.maxFieldType = n.maxFieldType;
node.idle = n.idle;
node.idleFieldType = n.idleFieldType;
node.user = n.user;
node.userFieldType = n.userFieldType;
node.password = n.password;
node.passwordFieldType = n.passwordFieldType;
node.connectionTimeout = n.connectionTimeout;
node.connectionTimeoutFieldType = n.connectionTimeoutFieldType;

this.pgPool = new Pool({
user: getField(node, n.userFieldType, n.user),
password: getField(node, n.passwordFieldType, n.password),
user: node.credentials.user,
password: node.credentials.password,
Comment on lines +77 to +78
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you think of a way to fall back to the existing credentials, in order to support a transition for the existing users?

host: getField(node, n.hostFieldType, n.host),
port: getField(node, n.portFieldType, n.port),
database: getField(node, n.databaseFieldType, n.database),
Expand All @@ -88,12 +85,18 @@ module.exports = function (RED) {
idleTimeoutMillis: getField(node, n.idleFieldType, n.idle),
connectionTimeoutMillis: getField(node, n.connectionTimeoutFieldType, n.connectionTimeout),
});

this.pgPool.on('error', (err, _) => {
node.error(err.message);
});
}

RED.nodes.registerType('postgreSQLConfig', PostgreSQLConfigNode);
RED.nodes.registerType('postgreSQLConfig', PostgreSQLConfigNode, {
credentials: {
user: { type: 'text' },
password: { type: 'password' },
},
});

function PostgreSQLNode(config) {
const node = this;
Expand Down