diff --git a/lib/main.js b/lib/main.js index 7e993c12..e1e5d8ce 100644 --- a/lib/main.js +++ b/lib/main.js @@ -36,7 +36,7 @@ let originalClientConnect; * @module pg-promise * * @description - * ## pg-promise v11.8 + * ## pg-promise v11.9 * All documentation here is for the latest official release only. * * ### Initialization Options diff --git a/lib/types/parameterized-query.js b/lib/types/parameterized-query.js index 96936ade..ab8b4e75 100644 --- a/lib/types/parameterized-query.js +++ b/lib/types/parameterized-query.js @@ -36,6 +36,7 @@ const npm = { * @param {array} [options.values] - See property {@link ParameterizedQuery#values values}. * @param {boolean} [options.binary] - See property {@link ParameterizedQuery#binary binary}. * @param {string} [options.rowMode] - See property {@link ParameterizedQuery#rowMode rowMode}. + * @param {ITypes} [options.types] - See property {@link ParameterizedQuery#types types}. * * @returns {ParameterizedQuery} * @@ -91,7 +92,7 @@ class ParameterizedQuery extends ServerFormatting { text: options }; } else { - options = assert(options, ['text', 'values', 'binary', 'rowMode']); + options = assert(options, ['text', 'values', 'binary', 'rowMode', 'types']); } super(options); } @@ -148,6 +149,10 @@ ParameterizedQuery.prototype.parse = function () { _i.target.rowMode = options.rowMode; } + if (options.types !== undefined) { + _i.target.types = options.types; + } + if (errors.length) { return _i.currentError = new ParameterizedQueryError(errors[0], _i.target); } @@ -238,6 +243,14 @@ module.exports = {ParameterizedQuery}; * - `array` will make all data rows arrive as arrays of values. By default, rows arrive as objects. */ +/** + * @name ParameterizedQuery#types + * @type {ITypes} + * @default undefined + * @description + * Custom type parsers just for this query result. + */ + /** * @name ParameterizedQuery#error * @type {errors.ParameterizedQueryError} diff --git a/lib/types/prepared-statement.js b/lib/types/prepared-statement.js index 21f89d31..fbc59c2e 100644 --- a/lib/types/prepared-statement.js +++ b/lib/types/prepared-statement.js @@ -38,6 +38,7 @@ const npm = { * @param {boolean} [options.binary] - See property {@link PreparedStatement#binary binary}. * @param {string} [options.rowMode] - See property {@link PreparedStatement#rowMode rowMode}. * @param {number} [options.rows] - See property {@link PreparedStatement#rows rows}. + * @param {ITypes} [options.types] - See property {@link PreparedStatement#types types}. * * @returns {PreparedStatement} * @@ -89,7 +90,7 @@ const npm = { */ class PreparedStatement extends ServerFormatting { constructor(options) { - options = assert(options, ['name', 'text', 'values', 'binary', 'rowMode', 'rows']); + options = assert(options, ['name', 'text', 'values', 'binary', 'rowMode', 'rows', 'types']); super(options); } @@ -192,6 +193,10 @@ PreparedStatement.prototype.parse = function () { _i.target.rows = options.rows; } + if (options.types !== undefined) { + _i.target.types = options.types; + } + if (errors.length) { return _i.currentError = new PreparedStatementError(errors[0], _i.target); } @@ -289,6 +294,14 @@ module.exports = {PreparedStatement}; * - `array` will make all data rows arrive as arrays of values. By default, rows arrive as objects. */ +/** + * @name PreparedStatement#types + * @type {ITypes} + * @default undefined + * @description + * Custom type parsers just for this query result. + */ + /** * @name PreparedStatement#error * @type {errors.PreparedStatementError} diff --git a/typescript/pg-promise.d.ts b/typescript/pg-promise.d.ts index dfcc1614..c8df0b19 100644 --- a/typescript/pg-promise.d.ts +++ b/typescript/pg-promise.d.ts @@ -15,6 +15,8 @@ // Follow the links below: // https://stackoverflow.com/questions/36593087/using-a-custom-promise-as-a-generic-type // https://github.com/Microsoft/TypeScript/issues/1213 +import {ITypes} from "./pg-subset"; + type XPromise = Promise; import * as pg from './pg-subset'; @@ -79,6 +81,7 @@ declare namespace pgPromise { binary?: boolean rowMode?: 'array' | null | void rows?: number + types?: ITypes; } interface IParameterizedQuery { @@ -86,6 +89,7 @@ declare namespace pgPromise { values?: any[] binary?: boolean rowMode?: void | 'array' + types?: ITypes; } interface IPreparedParsed { @@ -248,6 +252,7 @@ declare namespace pgPromise { binary: boolean; rowMode: void | 'array'; rows: number; + types: ITypes; parse(): IPreparedParsed | errors.PreparedStatementError @@ -267,6 +272,7 @@ declare namespace pgPromise { // advanced properties: binary: boolean; rowMode: void | 'array'; + types: ITypes; parse(): IParameterizedParsed | errors.ParameterizedQueryError