How to use the pg.native.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 nodetiles / nodetiles-core / datasources / PostGIS.js View on Github external
// minX = -122.4565;
    // minY = 37.756;
    // maxX = -122.451;
    // maxY = 37.761;
    
    var min = [minX, minY];
    var max = [maxX, maxY];

    // project request coordinates into data coordinates
    if (mapProjection !== this._projection) {
      min = projector.project.Point(mapProjection, this._projection, min);
      max = projector.project.Point(mapProjection, this._projection, max);
      // console.log(min,max);
    }
    
    pg.connect(this._connectionString, function(err, client) { // Switched method signature... WTF?!
      if (err) { console.error(err); return callback(err, null); }
      // console.log("Loading features...");
      var start, query;
        
      start = Date.now();
      if (this._attrFields) {
        query = "SELECT ST_AsGeoJson("+this._geomField+") as geometry, "+this._attrFields+" FROM "+this._tableName+" WHERE "+this._geomField+" && ST_MakeEnvelope($1,$2,$3,$4);";
      }
      else {
        query = "SELECT ST_AsGeoJson("+this._geomField+") as geometry,* FROM "+this._tableName+" WHERE "+this._geomField+" && ST_MakeEnvelope($1,$2,$3,$4);";
      }
      // console.log("Querying... "+query+" "+min+", "+max);
      client.query(query, [min[0], min[1], max[0], max[1]], function(err, result) {
        if (err) { return callback(err, null); }
        // console.log("Loaded in " + (Date.now() - start) + "ms");
github spacekit / spacekit-service / lib / db.js View on Github external
run (query, params, callback) {
    Pg.connect(this.connectionString, (err, client, done) => {
      if (err) {
        return callback(err);
      }

      client.query(query, params, (err, result) => {
        done(); // releases client

        callback(err, result);
      });
    });
  }
github spacekit / spacekit / util / db.js View on Github external
run (query, params, callback) {
    Pg.connect(this.config.pg, (err, client, done) => {
      if (err) {
        return callback(err);
      }

      client.query(query, params, (err, result) => {
        done(); // releases client

        callback(err, result);
      });
    });
  }
}
github jmafc / database-ui-tutorial / nodejs / server.js View on Github external
var execute = function(query, args, callback) {
  pg.connect(conString, function(err, client, done) {
    if (err) {
      console.log(err);
      return callback(err);
    }
    client.query(query, args, function(err, result) {
      done();
      if (err)
        console.log(err);
      callback(err, result);
    });
  });
};