Skip to content

Update index.js #26

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
49 changes: 22 additions & 27 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env node

var pg = require('pg');
const { Pool, Client } = require('pg')
var PostgresCouchDB = require('../lib');



// old notes from original branch
//Note there is an error in the simple example which i have not tracked down/fixed
//yet it will not restart the stream from where it left off if the feeder is stopped
//
Expand All @@ -14,33 +13,29 @@ var PostgresCouchDB = require('../lib');
var settings =
{
couchdb: {
url: 'http://192.168.3.21:5984',
pgtable: 'example',
database: 'example'
url: 'http://user:pass@ipAddress:5984',
pgtable: 'couch_import',
database: 'tcsmaster'
}
};

pgclient = new pg.Client("postgres://mike@localhost/pgdatabase");


pgclient.connect(function(err) {
if (err) {
if(err.code == 'ECONNREFUSED'){ //try to catch here but i dont think works
console.error('ERROR: Connection to postgres refused', err);
}else{
console.error('ERROR: Could not connect to postgres', err);
}
process.exit();
} else {
console.log('Connected to postgres');
}
}) ;


initial_since = get_initial_since(settings.couchdb.pgtable);

createImporter();

var pgclient = new Client({
user: 'user',
host: 'ipAddress',
database: 'tcs_import',
password: 'pass',
port: 5432,
});

pgclient
.connect()
.then(() => {
console.log('Connected to postgres');

initial_since = get_initial_since(settings.couchdb.pgtable);
createImporter();
})
.catch(err => console.error('connection error', err.stack))

function createImporter(){
settings.since = initial_since;
Expand Down