import * as pg from "pg"; var conString = "postgres://*****:*****@localhost/database"; // https://github.com/brianc/node-pg-types pg.types.setTypeParser(20, val => Number(val)); // Client pooling pg.defaults.ssl = true; pg.connect(conString, (err, client, done) => { if (err) { return console.error("Error fetching client from pool", err); } client.query("SELECT $1::int AS number", ["1"], (err, result) => { if (err) { done(err); return console.error("Error running query", err); } else { done(); } console.log(result.rows[0]["number"]); return null; }); return null; }); // Simple var client = new pg.Client(conString); client.connect(err => { if (err) {
import * as bookshelf from "bookshelf"; import * as knex from "knex"; import * as pg from "pg"; pg.defaults.ssl = true; // Fix for parsing of numeric fields pg.types.setTypeParser(1700, "text", parseFloat); import knexfile = require("./knexfile"); const dbConfig = knexfile[process.env.NODE_ENV]; export = bookshelf(knex(dbConfig));