Adding pg-types (#12037)

This commit is contained in:
James Bracy
2016-10-19 21:26:52 +09:00
committed by Masahiro Wakame
parent 03b3450d08
commit aa073574a3
3 changed files with 53 additions and 11 deletions
+18
View File
@@ -0,0 +1,18 @@
/// <reference path="pg-types.d.ts" />
/// <reference path="../moment/moment.d.ts" />
import * as types from "pg-types";
types.getTypeParser(1184, 'text');
types.setTypeParser(1184, (value) => value === null ? null : value);
types.setTypeParser(1186, 'text', (value) => value === null ? null : value);
types.setTypeParser(1186, 'binary', (value) => value.toISOString());
types.setTypeParser(1185, (value) => types.arrayParser.create(value, (x) => x).parse());
var TIMESTAMPTZ_OID = 1184
var TIMESTAMP_OID = 1114
var parseFn = function(val: any) {
return val === null ? null : moment(val)
}
types.setTypeParser(TIMESTAMPTZ_OID, parseFn)
types.setTypeParser(TIMESTAMP_OID, parseFn)
+23
View File
@@ -0,0 +1,23 @@
// Type definitions for pg-types 1.11.0
// Project: https://github.com/brianc/node-pg-types
// Definitions by: James Bracy <https://github.com/waratuman>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module "pg-types" {
interface TypeParser {
(value: any): any;
}
export function getTypeParser(oid: number, format: string): TypeParser;
export function setTypeParser(oid: number, format: string, parseFn: TypeParser): void;
export function setTypeParser(oid: number, parseFn: TypeParser): void;
export namespace arrayParser {
export function create(source: any, transform: TypeParser): { parse: () => any[] };
}
}
Vendored
+12 -11
View File
@@ -4,10 +4,12 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
/// <reference path="../pg-types/pg-types.d.ts" />
declare module "pg" {
import events = require("events");
import stream = require("stream");
import pgTypes = require("pg-types");
export function connect(connection: string, callback: (err: Error, client: Client, done: (err?: any) => void) => void): void;
export function connect(config: ClientConfig, callback: (err: Error, client: Client, done: (err?: any) => void) => void): void;
@@ -34,13 +36,13 @@ declare module "pg" {
}
export interface PoolConfig extends ClientConfig {
// properties from module 'node-pool'
max?: number;
min?: number;
refreshIdle?: boolean;
idleTimeoutMillis?: number;
reapIntervalMillis?: number;
returnToHead?: boolean;
// properties from module 'node-pool'
max?: number;
min?: number;
refreshIdle?: boolean;
idleTimeoutMillis?: number;
reapIntervalMillis?: number;
returnToHead?: boolean;
}
export interface QueryConfig {
@@ -90,7 +92,7 @@ declare module "pg" {
constructor(connection: string);
constructor(config: ClientConfig);
connect(callback?: (err:Error) => void): void;
connect(callback?: (err: Error) => void): void;
end(): void;
release(): void;
@@ -126,7 +128,6 @@ declare module "pg" {
public on(event: string, listener: Function): this;
}
export namespace types {
function setTypeParser<T>(typeId: number, parser: (value: string) => T): void;
}
export const types: typeof pgTypes;
}