How to use the pg.defaults 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 MeLlamoPablo / schedulebot / lib / modules / dbhandler / core.js View on Github external
"use strict";

const cfg            = require('../../modules/confighandler/cfg.js');
const moment         = require('moment');
const readEnv        = require('../../../setup/readEnv');
const path           = require('path');
const pg             = require('pg');

let connStr;

if (process.env.DATABASE_URL /* Running on heroku */) {
	connStr = process.env.DATABASE_URL;
	pg.defaults.ssl = true;
} else {
	let env = readEnv(path.join(__dirname, "../../../"));

	if (env === null) {
		console.error("Couldn't connect to the database!\n" +
			"The .ENV file was not found, or couldn't be parsed.");
		process.exit(1);
	}

	if (env.useSSL) {
		pg.defaults.ssl = true;
	}

	connStr = env.url;
}
github aepyornis / hpd / server.js View on Github external
'use strict';

const restify = require('restify');
const fs = require('fs');
const pg = require('pg');
const async = require('async');
const _ = require('lodash');
const config = require('./config');

// db settings
pg.defaults.database =  config.pg.database;
pg.defaults.host = config.pg.host;
pg.defaults.user = config.pg.user;
pg.defaults.password = config.pg.password;
if (config.pg.port) {
  pg.defaults.port = config.pg.port;
}

// server settings
const server_port = '8888';
const server_ip_address = '0.0.0.0';

const server = restify.createServer({
  name: 'Inside-HPD-Data'
});

server.listen(server_port, server_ip_address);
github aepyornis / hpd / server.js View on Github external
'use strict';

const restify = require('restify');
const fs = require('fs');
const pg = require('pg');
const async = require('async');
const _ = require('lodash');
const config = require('./config');

// db settings
pg.defaults.database =  config.pg.database;
pg.defaults.host = config.pg.host;
pg.defaults.user = config.pg.user;
pg.defaults.password = config.pg.password;
if (config.pg.port) {
  pg.defaults.port = config.pg.port;
}

// server settings
const server_port = '8888';
const server_ip_address = '0.0.0.0';

const server = restify.createServer({
  name: 'Inside-HPD-Data'
});

server.listen(server_port, server_ip_address);

// this functions runs for all requests
//server.use(function(req, res, next){
github fabienvauchelles / qscore / platform-engine / src / common / database / client.js View on Github external
'use strict';

// Postgres count parse fix
require('pg').defaults.parseInt8 = true;

const
    _ = require('lodash'),
    Sequelize = require('sequelize'),
    winston = require('winston');

const
    {retry} = require('../helpers'),
    Migration = require('../../migration');

const
    config = require('../../config');


const logging = config.node_env !== 'production';
github jbergant / chatbot-facebook-v2-final / app.js View on Github external
'use strict';

const dialogflow = require('dialogflow');
const config = require('./config');
const express = require('express');
const crypto = require('crypto');
const bodyParser = require('body-parser');
const request = require('request');
const app = express();
const uuid = require('uuid');
const pg = require('pg');
pg.defaults.ssl = true;

const broadcast = require('./routes/broadcast');
const webviews = require('./routes/webviews');

const userService = require('./services/user-service');
const colors = require('./colors');
const weatherService = require('./services/weather-service');
const jobApplicationService = require('./services/job-application-service');
let dialogflowService = require('./services/dialogflow-service');
const fbService = require('./services/fb-service');

const passport = require('passport');
const FacebookStrategy = require('passport-facebook').Strategy;
const session = require('express-session');

// Messenger API parameters
github opencollective / opencollective-api / server / models / index.js View on Github external
import pg from 'pg';
import Sequelize from 'sequelize';
import config from 'config';
import debug from 'debug';

import logger from '../lib/logger';
import { getDBConf } from '../lib/db';

// this is needed to prevent sequelize from converting integers to strings, when model definition isn't clear
// like in case of the key totalOrders and raw query (like User.getTopBackers())
pg.defaults.parseInt8 = true;

const dbConfig = getDBConf('database');

/**
 * Database connection.
 */
logger.info(`Connecting to postgres://${dbConfig.host}/${dbConfig.database}`);

// If we launch the process with DEBUG=psql, we log the postgres queries
if (process.env.DEBUG && process.env.DEBUG.match(/psql/)) {
  config.database.options.logging = true;
}

if (config.database.options.logging) {
  if (process.env.NODE_ENV === 'production') {
    config.database.options.logging = (query, executionTime) => {
github bigeasy / relatable / postgresql.js View on Github external
var pg = require("pg"),
    Mutator = require("./engine").Mutator,
    __slice = [].slice,
    cadence = require("cadence");

pg.defaults.parseFloat = false;
pg.defaults.hideDeprecationWarnings = true;

function die () {
  console.log.apply(console, __slice.call(arguments, 0));
  process.exit(1);
}

function say () { console.log.apply(console, __slice.call(arguments, 0)) }

exports.Engine = Engine;

Engine.name = 'Engine';

function Engine(_configuration) {
  this._configuration = _configuration;
}
github musicglue / pg-ts / src / getPool.ts View on Github external
import setupPoolAssertions from "./assertions";
import setupPoolEvents from "./events";
import {
  DbPool,
  PoolConfig,
  Transaction,
  TransactionScope,
  TransactionTask,
  TxIsolationLevel,
  TxOptions,
} from "./index";
import setupParsers from "./parsing";
import { PostProcessingConfig } from "./types";

pg.defaults.poolSize = parseInt(process.env.PG_POOL_SIZE || "10", 10);

const defaultTxOptions: TxOptions = {
  deferrable: false,
  isolation: "READ COMMITTED",
  readOnly: false,
};

const getIsolationStatement = (txOpts?: TxOptions): string => {
  const isolation: TxIsolationLevel = get(txOpts, "isolation", "READ COMMITTED");
  return `ISOLATION LEVEL ${isolation}`;
};

const transaction = (pool: DbPool): Transaction => {
  return t;

  function t(x: TxOptions, y: TransactionScope): Promise;
github jmcdo29 / zeldaPlay / server / db / knexfile.js View on Github external
require('dotenv').config({path: '../../.env'});
const pg = require('pg');

pg.defaults.ssl = true;

module.exports = {
  client: 'pg',
  connection: process.env.DATABASE_URL
}