本文整理匯總了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));