Changing import of types to use named variants instead of an aliased

module

When "pg-native" is not available, importing the module as a wildcard
after tsc transpilation can cause the runtime to invoke the getter
for the 'native' export, which will print an annoying message from
the runtime (node, etc):

"Cannot find module 'pg-native'"
This commit is contained in:
Alex Sherwin
2018-03-01 00:27:30 -05:00
parent 4bab2f7783
commit 88f695c16c

View File

@@ -1,10 +1,10 @@
import * as pg from "pg";
import { types, Client, QueryArrayConfig, Pool } from "pg";
// https://github.com/brianc/node-pg-types
// tslint:disable-next-line no-unnecessary-callback-wrapper
pg.types.setTypeParser(20, val => Number(val));
types.setTypeParser(20, val => Number(val));
const client = new pg.Client({
const client = new Client({
host: 'my.database-server.com',
port: 5334,
user: 'database-user',
@@ -65,7 +65,7 @@ client.query(query)
console.error(e.stack);
});
const queryArrMode: pg.QueryArrayConfig = {
const queryArrMode: QueryArrayConfig = {
name: 'get-name-array',
text: 'SELECT $1::text',
values: ['brianc'],
@@ -103,11 +103,11 @@ client.end()
.then(() => console.log('client has disconnected'))
.catch(err => console.error('error during disconnection', err.stack));
const poolOne = new pg.Pool({
const poolOne = new Pool({
connectionString: 'postgresql://dbuser:secretpassword@database.server.com:3211/mydb'
});
const pool = new pg.Pool({
const pool = new Pool({
host: 'localhost',
port: 5432,
user: 'database-user',