From e6d86c53a2b77281749db9cc51b4f40bb4983d3a Mon Sep 17 00:00:00 2001 From: Kibae Shin Date: Thu, 20 Apr 2017 10:14:26 +0700 Subject: [PATCH 1/3] Support for logical streaming replication --- lib/client.js | 4 ++++ lib/connection-parameters.js | 4 ++++ lib/connection.js | 3 +++ 3 files changed, 11 insertions(+) diff --git a/lib/client.js b/lib/client.js index 5d365dab5..13a62576e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -26,6 +26,7 @@ var Client = function(config) { this.port = this.connectionParameters.port; this.host = this.connectionParameters.host; this.password = this.connectionParameters.password; + this.replication = this.connectionParameters.replication; var c = config || {}; @@ -222,6 +223,9 @@ Client.prototype.getStartupConf = function() { if (appName) { data.application_name = appName; } + if (params.replication) { + data.replication = params.replication === true ? 'true' : params.replication; + } return data; }; diff --git a/lib/connection-parameters.js b/lib/connection-parameters.js index 68658eff0..9e03cf9d1 100644 --- a/lib/connection-parameters.js +++ b/lib/connection-parameters.js @@ -57,6 +57,7 @@ var ConnectionParameters = function(config) { this.binary = val('binary', config); this.ssl = typeof config.ssl === 'undefined' ? useSsl() : config.ssl; this.client_encoding = val("client_encoding", config); + this.replication = val("replication", config); //a domain socket begins with '/' this.isDomainSocket = (!(this.host||'').indexOf('/')); @@ -88,6 +89,9 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) { if(this.database) { params.push("dbname='" + this.database + "'"); } + if(this.replication) { + params.push("replication='" + (this.database === true ? "true" : this.replication) + "'"); + } if(this.host) { params.push("host=" + this.host); } diff --git a/lib/connection.js b/lib/connection.js index 59247a7c4..7318287c2 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -425,6 +425,9 @@ Connection.prototype.parseMessage = function(buffer) { case 0x48: //H return this.parseH(buffer, length); + case 0x57: //W + return new Message('replicationStart', length); + case 0x63: //c return new Message('copyDone', length); From f1d3caecd1891875aeef322c9bf08a9160b84d85 Mon Sep 17 00:00:00 2001 From: Kibae Shin Date: Thu, 20 Apr 2017 12:24:11 +0700 Subject: [PATCH 2/3] Wrong compare expr in getLibpqConnectionString --- lib/connection-parameters.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/connection-parameters.js b/lib/connection-parameters.js index 9e03cf9d1..35fe3a556 100644 --- a/lib/connection-parameters.js +++ b/lib/connection-parameters.js @@ -90,7 +90,7 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) { params.push("dbname='" + this.database + "'"); } if(this.replication) { - params.push("replication='" + (this.database === true ? "true" : this.replication) + "'"); + params.push("replication='" + (this.replication === true ? "true" : this.replication) + "'"); } if(this.host) { params.push("host=" + this.host); From 059a2fcef1266d57cd5959e10966a473e148ba89 Mon Sep 17 00:00:00 2001 From: Kibae Shin Date: Thu, 20 Apr 2017 15:55:19 +0700 Subject: [PATCH 3/3] Simplify codes for replication parameter --- lib/client.js | 2 +- lib/connection-parameters.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index 13a62576e..1bb27ea22 100644 --- a/lib/client.js +++ b/lib/client.js @@ -224,7 +224,7 @@ Client.prototype.getStartupConf = function() { data.application_name = appName; } if (params.replication) { - data.replication = params.replication === true ? 'true' : params.replication; + data.replication = '' + params.replication; } return data; diff --git a/lib/connection-parameters.js b/lib/connection-parameters.js index 35fe3a556..c1c535e98 100644 --- a/lib/connection-parameters.js +++ b/lib/connection-parameters.js @@ -90,7 +90,7 @@ ConnectionParameters.prototype.getLibpqConnectionString = function(cb) { params.push("dbname='" + this.database + "'"); } if(this.replication) { - params.push("replication='" + (this.replication === true ? "true" : this.replication) + "'"); + params.push("replication='" + this.replication + "'"); } if(this.host) { params.push("host=" + this.host);