How to use the pg.js.connect function in pg

To help you get started, we’ve selected a few pg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nodebugme / site / start.js View on Github external
spawn('createdb', ['nodebugme']).on('exit', function(code) {
      if (code) {
        console.log('failed! (tried "createdb nodebugme")')
        return process.exit(1)
      }
      console.log('done.')

      process.stdout.write('setting up "nodebugme" tables... ')
      pg.connect(json.server.plugins.database, function(err, client, done) {
        if (err) {
          console.log('failed! (%s)', err.message)
          return process.exit(1)
        }

        migrate(client, function(err) {
          if (err) {
            console.log('failed! (%s)', err.message)
            return process.exit(1)
          }

          console.log('done.')
          process.stdout.write('getting credentials for github sync... ')
          ghauth({
            noSave: true,
            scopes: ['user'],
github alfateam / rdb / examples / getMany2.js View on Github external
function onRun() {
	newChangeSet();
	pg.connect(conString, function(err, client, done) { 
    if (err) {
        console.log('Error while connecting: ' + err);  
        done();
        return;       	    	
    }
	domain.dbClient = client;
    domain.done = done;    
    runDbTest();
	});
}
github alfateam / rdb / examples / getMany.js View on Github external
function onRun() {
	newChangeSet();
	pg.connect(conString, function(err, client, done) { 
    if (err) {
        console.log('Error while connecting: ' + err);  
        done();
        return;       	    	
    }
	domain.dbClient = client;
    domain.done = done;    
    runDbTest();
	});
}
github didit-tech / FastLegS / lib / pg_setup.js View on Github external
return function query(text, values, cb) {
    if (typeof values === 'function') {
      cb = values;
      values = [];
    }
    pg.connect(connString, function(err, client, done) {
      if (err) return cb(err);
      client.query(text, values, function(err, result) {
        done();
        if (err) return cb(err);
        return cb(err, result.rows, result);
      });
    });
  };
};
github nodebugme / site / lib / plugins / database.js View on Github external
function onrequest(request, next) {
    var needsTransaction = request.route.handler && request.route.handler.needsTransaction

    pg.connect(options, function(err, client, done) {
      if (err) {
        return next(err)
      }

      cache.set(request, {release: done, client: client})
      request.db = client
      request.querybox = getQueryBox(
        options.analyze ?
          executeAnalyze.bind(client) :
          executeQuery.bind(client)
      )

      needsTransaction = needsTransaction && !client.inTransaction
      if (needsTransaction) return client.query('BEGIN', function(err) {
        debugDB('start transaction')
        if (err) {
github nodebugme / site / sync-gh-issues.js View on Github external
}

  var config = require('./config.json')
  ready = once(ready)

  var github = new Github({
      version: '3.0.0'
    , protocol: 'https'
  })

  github.authenticate({
      type: 'oauth'
    , token: config.githubSyncToken
  })

  pg.connect(config.server.plugins.database, function(err, client, done) {
    if (err) {
      return ready(err)
    }

    var qbox = getQuerybox(function(qobj, ready) {
      client.query(qobj.text, qobj.values, ready)
    })

    client.query('SELECT id, nbm_repo.user, name FROM nbm_repo', function (err, results) {
      if (err) return ready(err)

      var pending = results.rows.length

      if (!pending) return end()

      results.rows.forEach(function(repo) {