How to use the pg.Client.prototype 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 brianc / node-pg-pool / test / connection-timeout.js View on Github external
it('continues processing after a connection failure', (done) => {
    const Client = require('pg').Client
    const orgConnect = Client.prototype.connect
    let called = false

    Client.prototype.connect = function (cb) {
      // Simulate a failure on first call
      if (!called) {
        called = true

        return setTimeout(() => {
          cb(connectionFailure)
        }, 100)
      }
      // And pass-through the second call
      orgConnect.call(this, cb)
    }

    const pool = new Pool({
github brianc / node-pg-pool / test / connection-timeout.js View on Github external
it('continues processing after a connection failure', (done) => {
    const Client = require('pg').Client
    const orgConnect = Client.prototype.connect
    let called = false

    Client.prototype.connect = function (cb) {
      // Simulate a failure on first call
      if (!called) {
        called = true

        return setTimeout(() => {
          cb(connectionFailure)
        }, 100)
      }
      // And pass-through the second call
      orgConnect.call(this, cb)
    }

    const pool = new Pool({
      Client: Client,
      connectionTimeoutMillis: 1000,
      max: 1
github lematt1991 / BeerFeed / __tests__ / twitter-bot.js View on Github external
it('Tweets about good beers', done => {
		var bot = new TwitterBot('username', 'token', 'token_secret')

		var queryStub = sinon.stub(Client.prototype, 'query').callsFake(query => new Promise((resolve, reject) => {
			resolve({
				rows : [{
					beer : 'Abraxas',
					bid : 77322,
					venue_id : 3803461,
					count : 9,
					rating : 4.44918012619019,
					date : '2017-02-04 00:07:28',
					username : 'nyc_feed',
					brewery : 'Perennial Artisan Ales',
					venue : 'As Is NYC',
					twitter : '@asisnyc'
				}]
			})
		}))
github lematt1991 / BeerFeed / __tests__ / twitter-bot.js View on Github external
beforeAll(() => {
		connectStub = sinon.stub(Client.prototype, 'connect')
		TwitterBot = require('../backend/twitter-bot').TwitterBot
		TWITTER_KEY = process.env.TWITTER_KEY
		process.env.TWITTER_KEY = 'twitter_key'
		TWITTER_SECRET = process.env.TWITTER_SECRET
		process.env.TWITTER_SECRET = 'twitter_secret'
		toISOStub = sinon.stub(Date.prototype, 'toISOString').callsFake(() => 'fake-time');
	})