Skip to content

Commit 37f41f5

Browse files
authored
Update OID type (denodrivers#463)
* chore: update oid types * chore: update package version
1 parent c9d874e commit 37f41f5

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

connection/connection_params.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { parseConnectionUri } from "../utils/utils.ts";
22
import { ConnectionParamsError } from "../client/error.ts";
33
import { fromFileUrl, isAbsolute } from "../deps.ts";
4-
import { OidKey } from "../query/oid.ts";
4+
import { OidType } from "../query/oid.ts";
55

66
/**
77
* The connection string must match the following URI structure. All parameters but database and user are optional
@@ -92,9 +92,17 @@ export interface TLSOptions {
9292
caCertificates: string[];
9393
}
9494

95+
/**
96+
* The strategy to use when decoding results data
97+
*/
9598
export type DecodeStrategy = "string" | "auto";
99+
/**
100+
* A dictionary of functions used to decode (parse) column field values from string to a custom type. These functions will
101+
* take precedence over the {@linkcode DecodeStrategy}. Each key in the dictionary is the column OID type number or Oid type name,
102+
* and the value is the decoder function.
103+
*/
96104
export type Decoders = {
97-
[key in number | OidKey]?: DecoderFunction;
105+
[key in number | OidType]?: DecoderFunction;
98106
};
99107

100108
/**

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"lock": false,
33
"name": "@bartlomieju/postgres",
4-
"version": "0.18.0",
4+
"version": "0.18.1",
55
"exports": "./mod.ts"
66
}

mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export { Oid, OidTypes } from "./query/oid.ts";
1010
// TODO
1111
// Remove the following reexports after https://doc.deno.land
1212
// supports two level depth exports
13-
export type { OidKey, OidType } from "./query/oid.ts";
13+
export type { OidType, OidValue } from "./query/oid.ts";
1414
export type {
1515
ClientOptions,
1616
ConnectionOptions,

query/decode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Oid, OidType, OidTypes } from "./oid.ts";
1+
import { Oid, OidTypes, OidValue } from "./oid.ts";
22
import { bold, yellow } from "../deps.ts";
33
import {
44
decodeBigint,
@@ -218,7 +218,7 @@ export function decode(
218218
if (controls?.decoders) {
219219
// check if there is a custom decoder by oid (number) or by type name (string)
220220
const decoderFunc = controls.decoders?.[column.typeOid] ||
221-
controls.decoders?.[OidTypes[column.typeOid as OidType]];
221+
controls.decoders?.[OidTypes[column.typeOid as OidValue]];
222222

223223
if (decoderFunc) {
224224
return decoderFunc(strValue, column.typeOid);

query/oid.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
export type OidKey = keyof typeof Oid;
2-
export type OidType = (typeof Oid)[OidKey];
1+
/** A Postgres Object identifiers (OIDs) type name. */
2+
export type OidType = keyof typeof Oid;
3+
/** A Postgres Object identifiers (OIDs) numeric value. */
4+
export type OidValue = (typeof Oid)[OidType];
35

46
/**
5-
* Oid is a map of OidKey to OidType.
7+
* A map of OidType to OidValue.
68
*/
79
export const Oid = {
810
bool: 16,
@@ -175,11 +177,10 @@ export const Oid = {
175177
} as const;
176178

177179
/**
178-
* OidTypes is a map of OidType to OidKey.
179-
* Used to decode values and avoid search iteration
180+
* A map of OidValue to OidType. Used to decode values and avoid search iteration.
180181
*/
181182
export const OidTypes: {
182-
[key in OidType]: OidKey;
183+
[key in OidValue]: OidType;
183184
} = {
184185
16: "bool",
185186
17: "bytea",

0 commit comments

Comments
 (0)