pg-logical-replication
Version:
PostgreSQL Location Replication client - logical WAL replication streaming
41 lines (40 loc) • 1.47 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProtocolBuffersPlugin = void 0;
const abstract_plugin_js_1 = require("../abstract.plugin.js");
const pg_logicaldec_proto_js_1 = __importDefault(require("./pg_logicaldec.proto.js"));
class ProtocolBuffersPlugin extends abstract_plugin_js_1.AbstractPlugin {
proto;
rowMessage;
constructor(options) {
super(options || {});
try {
const protobufjs = require('protobufjs');
this.proto = protobufjs.Root.fromJSON(pg_logicaldec_proto_js_1.default);
this.rowMessage = this.proto.lookupType('RowMessage');
}
catch (e) {
console.error(`To use decoderbufs decoder, you need to install protobufjs package.
https://github.com/protobufjs/protobuf.js`);
throw e;
}
}
get name() {
return 'decoderbufs';
}
async start(client, slotName, lastLsn) {
const options = [];
let sql = `START_REPLICATION SLOT "${slotName}" LOGICAL ${lastLsn}`;
if (options.length > 0)
sql += ` (${options.join(' , ')})`;
// console.log(sql);
return client.query(sql);
}
parse(buffer) {
return this.rowMessage.decode(buffer);
}
}
exports.ProtocolBuffersPlugin = ProtocolBuffersPlugin;