本文整理汇总了TypeScript中pg.types类的典型用法代码示例。如果您正苦于以下问题:TypeScript types类的具体用法?TypeScript types怎么用?TypeScript types使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了types类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Number
import * as pg from "pg";
var conString = "postgres://username:password@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) {
示例2: require
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));