Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* global describe, before, it */
'use strict';
var co = require('co'),
should = require('chai').should(),
pg = require('../lib')(require('pg').native),
testHelper = require('./test-helper');
var query = 'select name from person order by name';
describe('CoClient-Native', function() {
var connString = null;
before(function() {
return co(function*() {
var config = yield testHelper.getConfig();
connString = config.connectionStrings.main;
});
});
describe('#connectPromise()', function() {
var expect = require('chai').expect;
var sinon = require('sinon');
var pg = require('pg').native;
var PostGISSource = require(__dirname + '/../datasources/PostGIS');
var async = require('async');
var __ = require('lodash')
var source = new PostGISSource({
connectionString: process.env.DATABASE_URL || "tcp://postgres@localhost/postgis", //required
tableName: "rpd_parks", // required
geomField: "wkb_geometry", // required
fields: "map_park_n, ogc_fid", //faster if you specify fields, but optional
name: "sf_parks", // optional, defaults to table name
projection: "EPSG:4326" // Lat/Long
});
describe('PostGIS Data Source', function() {
* @private
* @author Özüm Eldoğan
* @example
* var executeSQLFiles = require('./sql/execute-sql-files');
* executeSQLFiles(client, ['public'])
* .then((result) => {
* console.log(result.getCollection('table').find({fullName: 'public.account'})); // table.sql query result
* })
* .catch((err) => {
* console.log(err);
* client.end();
* });
*/
'use strict';
try {
var pg = require('pg').native;
} catch (err) {
pg = require('pg');
}
var inflection = require('inflection');
var readSQLFiles = require('./read-sql-files');
var Loki = require('lokijs');
var DB = require('../../lib/db');
var Schema = require('../../lib/schema');
var Table = require('../../lib/table');
var Column = require('../../lib/column');
var Constraint = require('../../lib/constraint');
var RelationFabricator = require('../lib/util/relation-fabricator.js');
var Index = require('../../lib/index.js');
var config = {
new Promise((resolve, reject) => {
const defaultConnection = Object.assign({}, connection, {
// This database is assumed to exist. If it doesn't, no problem,
// a database creation attempt won't be made in that case.
database: 'postgres'
})
const Client = isNative ? pg.native.Client : pg.Client
const client = new Client(defaultConnection)
client.connect(error =>
// In case the default `postgres` database doesn't exist, just skip
// this part.
error ? resolve() :
// Attempt to create the database specified in the options.
client.query(`create database "${connection.database}"`,
// Ignore errors and result here.
() => {
// Just disconnect after an attempt has been made.
client.end((error) => error ? reject(error) : resolve())
}))
}) : Promise.resolve())
import { expect } from 'chai';
import Pg, { SQL } from '../../src/index';
const tableName = 'pgAsyncTest';
testWithDriver('pg', require('pg'));
testWithDriver('pg.native', require('pg').native);
function testWithDriver(driverName, driver) {
describe(`pg-async SQL tag (with ${driverName} driver)`, () => {
let pg;
before(async () => {
pg = new Pg(null, driver);
await pg.query(SQL`
CREATE TABLE IF NOT EXISTS $ID${tableName} (
id serial,
val integer
)
`);
});
after(async () => {
createPool(databaseUrl: string, options: Object) {
const { auth, hostname, port, pathname } = url.parse(databaseUrl);
const [ user, password ] = (auth || '').split(':');
const config = {
...options,
user: user,
password: password,
host: hostname,
port: port,
database: (pathname || '').slice(1),
ssl: process.env.LEGO_DISABLE_SSL !== 'true',
};
const internal = pg.native ? pg.native : pg;
this.pool = new internal.Pool(config);
this.pool.on('error', () => {
//
});
}
exports.connect = function(config, callback) {
if (config.native) { pg = pg.native; }
var db = config.db || new pg.Client(config);
callback(null, new PgDriver(db));
};
"use strict";
/*jslint node: true */
var pg = require('pg').native;
var Promise = require("bluebird");
const CONF = require("./conf");
var pool_conf = {
user: CONF.postgresUser,
database: CONF.postgres_database,
password: CONF.postgres_password,
host: CONF.postgres_url,
port: CONF.postgres_port,
max: 10,
idleTimeoutMillis: 30000,
};
var accessors = {
get_tick_time_differences(pool, table, start_time, end_time){
var pg = require('pg')
, Transaction = require('any-db').Transaction
, pgNative = null
try { pgNative = pg.native } catch (__e) {}
exports.forceJS = false
exports.createConnection = function (opts, callback) {
var backend = chooseBackend()
, conn = new backend.Client(opts)
conn.begin = begin
if (callback) {
conn.connect(function (err) {
if (err) callback(err)
else callback(null, conn)
})
} else {
conn.connect()
require('babel-core/register')({
presets: ['es2015', 'react']
});
var http = require('http'),
fs = require('fs'),
Twig = require("twig"),
express = require('express'),
formidable = require("formidable"),
pg = require('pg').native,
React = require('react'),
createStore = require('redux').createStore,
endpoints = require('./_build/js/model/endpoints'),
reducer = require('./_build/js/model/reducers'),
ReactDOM = require('react-dom/server'),
store = require('./_build/js/model/store'),
actions = require('./_build/js/model/actions'),
ToDoForm = require('./_build/js/view/todoform'),
ArchiveForm = require('./_build/js/view/archiveform'),
app = express(),
compression = require('compression'),
minifyHTML = require('express-minify-html'),
isProd = (process.env.NODE_ENV == 'production') ? true : false;
pg.defaults.ssl = true;