How to use pg-connection-string - 10 common examples

To help you get started, we’ve selected a few pg-connection-string 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 graphile / postgraphile / src / main.js View on Github external
anonymousRole,
    hostname = 'localhost',
    port = 3000,
    development = false,
    route = '/',
    secret,
    maxPoolSize = 10,
  } = program

  if (!connection)
    throw new Error('Must define a PostgreSQL connection string to connect to.')

  // Parse out the connection string into an object and attach a
  // `poolSize` option.
  const pgConfig = {
    ...parseConnectionString(connection),
    poolSize: maxPoolSize,
  }

  // Create the GraphQL HTTP server.
  const handler = postgraphql(pgConfig, schemaName, {
    anonymousRole,
    route,
    secret,
    development,
  })

  http.createServer(handler).listen(port, hostname, () => {
    console.log(`GraphQL server listening at http://${hostname}:${port}${route} 🚀`)
  })
}
github sasha-alias / sqltabs / src / connectors / postgres / PqClient.js View on Github external
if (!redshift){ // redhsift doesn't support this
                params = "application_name=sqltabs";
            }
        }
        connstr = util.format('%s//%s%s%s%s?%s',
            parsed.protocol,
            (parsed.auth == null) ? '' : parsed.auth,
            (password == null) ? '' : ':'+password,
            (parsed.host == null) ? '' : '@'+parsed.host,
            (parsed.path == null) ? '' : parsed.pathname,
            params
        );

        connstr = decodeURIComponent(connstr).trim();

        connstr = parseConnstr(connstr);
        if (connstr.database == null){
            connstr.database = connstr.user;
        }
        return connstr;
    }
};
github coatyio / coaty-js / src / db / adapters / postgres-adapter.ts View on Github external
private _getPoolOptions(connectionInfo: DbConnectionInfo): PoolConfig {
        const connString = connectionInfo.connectionString;
        let config: PoolConfig = {};

        // First extract options from connection string
        if (connString && connString.length > 0) {
            config = parse(connString);
        }

        // Then merge with options from connectionOptions
        if (connectionInfo.connectionOptions) {
            Object.assign(config, connectionInfo.connectionOptions);
        }

        return config as PoolConfig;
    }
github madd512 / simple-postgres / src / index.js View on Github external
function configure (server) {
  if (typeof server === 'string') {
    server = Object.assign(
      parseConnectionString(server),
      parseUrl(server, true).query // add query parameters
    )
  } else if (typeof server === 'undefined') {
    server = {}
  }

  for (let v of ['ssl', 'keepAlive', 'binary']) {
    if (typeof server[v] === 'string') {
      server[v] = server[v] !== 'false'
    }
  }
  for (let v of ['idleTimeoutMillis', 'poolSize', 'max', 'statement_timeout']) {
    if (typeof server[v] === 'string') {
      server[v] = server[v] === 'false' ? false : Number(server[v])
    }
  }
github graphile / migrate / src / settings.ts View on Github external
const shadowConnectionString = await check(
    "shadowConnectionString",
    (rawShadowConnectionString = process.env.SHADOW_DATABASE_URL) => {
      if (requireShadow) {
        if (typeof rawShadowConnectionString !== "string") {
          throw new Error(
            "Expected a string, or for TEST_DATABASE_URL to be set"
          );
        }
        return rawShadowConnectionString;
      }
      return null;
    }
  );
  const { database: shadowDatabaseName } = parse(shadowConnectionString || "");

  await check("pgSettings", pgSettings => {
    if (pgSettings) {
      if (typeof pgSettings !== "object" || pgSettings === null) {
        throw new Error("Expected settings.pgSettings to be an object");
      }
      const badKeys = Object.keys(pgSettings).filter(key => {
        const value = pgSettings[key];
        return typeof value !== "string" && typeof value !== "number";
      });
      if (badKeys.length) {
        throw new Error(
          `Invalid pgSettings for keys '${badKeys.join(
            ", "
          )}' - expected string` /* Number is acceptable, but prefer string. Boolean not acceptable. */
        );
github graphile / graphile-engine / packages / postgraphile-core / __tests__ / helpers.js View on Github external
const withTransactionlessPgClient = async (url, fn) => {
  if (!fn) {
    fn = url;
    url = process.env.TEST_DATABASE_URL;
  }
  const pgPool = new pg.Pool(pgConnectionString.parse(url));
  try {
    const client = await pgPool.connect();
    try {
      return await fn(client);
    } finally {
      await client.release();
    }
  } finally {
    await pgPool.end();
  }
};
github mariusandra / insights / packages / insights-api / src / insights / structure / generators / postgres.ts View on Github external
export default async function postgresGenerator (database: string): Promise {
  const dbConfig = parse(database)
  const db = await pgStructure(dbConfig, ['public'])
  const tablesArray = db.get('public').tables

  let structure: Structure = {}
  let multiples = {}

  tablesArray.forEach(table => {
    const name = table.name
    const model = changeCase.pascalCase(singular(name))

    structure[model] = structure[model] || {
      enabled: true,
      model: model,
      table_name: name,
      columns: {},
      custom: {},
github RisingStack / risingstack-bootcamp / models / db / config.js View on Github external
PG_SSL_CA: joi.string(),
  PG_SSL_KEY: joi.string(),
  PG_SSL_CERT: joi.string(),
  PG_SSL_ALLOW_UNAUTHORIZED: joi.boolean().truthy('true').falsy('false').default(true),
  PG_POOL_MIN: joi.number().integer().default(1),
  PG_POOL_MAX: joi.number().integer().default(20),
  PG_HEALTH_CHECK_TIMEOUT: joi.number().integer().default(2000)
}).unknown()
  .required()

const envVars = joi.attempt(process.env, envVarsSchema)

const config = {
  client: 'pg',
  connection: Object.assign(
    parse(envVars.PG_URI),
    envVars.PG_SSL_CA || envVars.PG_SSL_KEY || envVars.PG_SSL_CERT
      ? {
        ssl: {
          ca: envVars.PG_SSL_CA,
          key: envVars.PG_SSL_KEY,
          cert: envVars.PG_SSL_CERT,
          rejectUnauthorized: !envVars.PG_SSL_ALLOW_UNAUTHORIZED
        }
      }
      : {}
  ),
  pool: {
    min: envVars.PG_POOL_MIN,
    max: envVars.PG_POOL_MAX
  },
  migrations: {
github Noznoc / geojson-api / node_modules / pg / lib / connection-parameters.js View on Github external
var ConnectionParameters = function(config) {
  config = typeof config == 'string' ? parse(config) : (config || {});
  this.user = val('user', config);
  this.database = val('database', config);
  this.port = parseInt(val('port', config), 10);
  this.host = val('host', config);
  this.password = val('password', config);
  this.binary = val('binary', config);
  this.ssl = config.ssl || useSsl();
  this.client_encoding = val("client_encoding", config);
  //a domain socket begins with '/'
  this.isDomainSocket = (!(this.host||'').indexOf('/'));

  this.application_name = val('application_name', config, 'PGAPPNAME');
  this.fallback_application_name = val('fallback_application_name', config, false);
};
github mariusandra / insights / packages / insights-core / app / insights / structure / generators / postgres.js View on Github external
module.exports = async function postgresGenerator (database) {
  const dbConfig = parse(database)
  const db = await pgStructure(dbConfig, ['public'])
  const tablesArray = db.get('public').tables

  let structure = {}
  let multiples = {}

  tablesArray.forEach(table => {
    const name = table.name
    const model = changeCase.pascalCase(singular(name))

    structure[model] = structure[model] || {
      enabled: true,
      model: model,
      table_name: name,
      columns: {},
      custom: {},

pg-connection-string

Functions for dealing with a PostgresSQL connection string

MIT
Latest version published 3 months ago

Package Health Score

89 / 100
Full package analysis

Popular pg-connection-string functions