How to use the pg.native.Client 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 voodootikigod / migrator / lib / migrator.js View on Github external
var editor = "$EDITOR";
  if (options && options.editor) {
    editor = options.editor;
  }

  var db, OPEN_TRANSACTION, CLOSE_TRANSACTION;

  // determine working condition.
  if (app_config.postgresql) {
    // load postgresql library
    var postgres = require("pg").native;

    // create and connect db
    db = new postgres.Client(app_config.postgresql);
    db.connect();
    OPEN_TRANSACTION = "BEGIN; ";
    CLOSE_TRANSACTION = "COMMIT; ";

  } else if (app_config.mysql) {
    var mysql = require("mysql");

    // create and connect db
    db = mysql.createClient(app_config.mysql);
    OPEN_TRANSACTION = "START TRANSACTION; ";
    CLOSE_TRANSACTION = "COMMIT; ";

  } else {
    console.log("You must specify a connection string for either PostgreSQL or MySQL");
    process.exit(-1);
github jpdevries / matboard / labs / manage-users / server.js View on Github external
return new Promise(function(resolve, reject) {
    // instantiate a new client
    // the client will read connection information from
    // the same environment varaibles used by postgres cli tools
    var client = new pg.Client(process.env.DATABASE_URL);

    // connect to our database
    client.connect(function (err) {
      if (err) throw err;

      // execute a query on our database
      client.query(`
        SELECT modx_users.username, modx_users.user_id as id, user_group, role, name as groupname, givenname, familyname, email, slack, title, active, sudo FROM modx_users INNER JOIN modx_member_groups ON modx_member_groups.member = modx_users.user_id INNER JOIN modx_membergroup_names ON modx_member_groups.user_group = modx_membergroup_names.id INNER JOIN modx_user_attributes ON modx_user_attributes.id = modx_users.user_id ${where};
        `, function (err, result) {
        if (err) reject(err);

        // disconnect the client
        client.end(function (err) {

          if (err) reject(err);
        });
github jpdevries / matboard / labs / manage-users / server.js View on Github external
return new Promise(function(resolve, reject){
    var client = new pg.Client(process.env.DATABASE_URL);

    client.connect(function (err) {
      if (err) throw err;

      // execute a query on our database
      client.query(`
        SELECT * FROM "modx_membergroup_names" ${where};
        `, function (err, results) {
        if (err) reject(err);

        // disconnect the client
        client.end(function (err) {
          if (err) reject(err);
        });

        resolve(results.rows);
github LiveTex / Node-Pg / benchmarks / postgres.js View on Github external
var pg = require('pg').native;


var count = 0;
var step = 1;
var query = process.argv[3]  || "SELECT 1";


var r = 0;
var e = 0;
var t = Date.now();
var mem = 0;


var client = new pg.Client('tcp://postgres:123@' + process.argv[2] +  '/postgres');
client.connect(function() {
  function exec() {
    client.query(query, callback);
  }

  function callback(err) {
    if (err !== null) {
      e += 1;
    }

    mem += process.memoryUsage().heapUsed/1024/1024;

    if ((r += 1) === count) {
      console.log('[NODE-POSTGRES] | R:', r, ' | E:', e, ' | T:', Date.now() - t, ' | M:', (Math.round(mem/r*10)/10));
      run();
    }
github osmlab / to-fix / lib / import.js View on Github external
function connect(callback) {
    var client = new pg.Client(conString);
    client.connect(function(err) {
        if (err) return endClientErr(client, err);
        callback(client);
    });
}
github socrata / opendatanetwork.com / tasks / schema.js View on Github external
var pg = require('pg').native, 
    connectionString = process.env.DATABASE_URL || 'postgres://localhost:5432/census', 
    client, 
    query;

client = new pg.Client(connectionString);
client.connect();

query = client.query(
    "CREATE TABLE portals (portal_id bigserial primary key, title varchar(255), url varchar(255), housing smallint, restaurant_inspections smallint, transit smallint, health smallint, crime smallint, permits smallint);" +
    "INSERT INTO portals (title, url, housing, restaurant_inspections, transit, health, crime, permits) VALUES ('Australian Capital Territory', 'https://www.data.act.gov.au', '', 0, 0, 0, 0, 0, 0);"
    );
query.on('end', function() { client.end(); });
github JimAllanson / lifejs / schema.js View on Github external
var pg = require('pg').native
    , connectionString = process.env.DATABASE_URL
    , client
    , query;

client = new pg.Client(connectionString);
client.connect();

 query = client.query('CREATE TABLE data (data text)');
    query.on('end', function() { client.end(); });
github ozum / pg-structure / module_files / sql / legacy / execute-sql-files.js View on Github external
return new Promise((resolve, reject) => {
        if (isPgClient(pgOptions)) return resolve(pgOptions);
        let client = new pg.Client(pgOptions);

        client.connect((err) => {
            if (err) return reject(new Error(err));
            return resolve(client);
        });
    });
}
github alexyoung / dailyjs-heroku-postgres / schema.js View on Github external
var pg = require('pg').native
  , connectionString = process.env.DATABASE_URL || 'postgres://localhost:5432/dailyjs'
  , client
  , query;

client = new pg.Client(connectionString);
client.connect();
query = client.query('CREATE TABLE visits (date date)');
query.on('end', function() { client.end(); });