Skip to content

Commit

Permalink
adding types property to config queries
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jul 4, 2024
1 parent cc97187 commit 308d7ba
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion lib/types/parameterized-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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}
Expand Down
15 changes: 14 additions & 1 deletion lib/types/prepared-statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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}
Expand Down
6 changes: 6 additions & 0 deletions typescript/pg-promise.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = Promise<T>;

import * as pg from './pg-subset';
Expand Down Expand Up @@ -79,13 +81,15 @@ declare namespace pgPromise {
binary?: boolean
rowMode?: 'array' | null | void
rows?: number
types?: ITypes;
}

interface IParameterizedQuery {
text?: string | QueryFile
values?: any[]
binary?: boolean
rowMode?: void | 'array'
types?: ITypes;
}

interface IPreparedParsed {
Expand Down Expand Up @@ -248,6 +252,7 @@ declare namespace pgPromise {
binary: boolean;
rowMode: void | 'array';
rows: number;
types: ITypes;

parse(): IPreparedParsed | errors.PreparedStatementError

Expand All @@ -267,6 +272,7 @@ declare namespace pgPromise {
// advanced properties:
binary: boolean;
rowMode: void | 'array';
types: ITypes;

parse(): IParameterizedParsed | errors.ParameterizedQueryError

Expand Down

0 comments on commit 308d7ba

Please sign in to comment.