Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions connection/connection_params.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parseConnectionUri } from "../utils/utils.ts";
import { ConnectionParamsError } from "../client/error.ts";
import { fromFileUrl, isAbsolute } from "../deps.ts";
import { OidKey } from "../query/oid.ts";
import { OidType } from "../query/oid.ts";

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

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

/**
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lock": false,
"name": "@bartlomieju/postgres",
"version": "0.18.0",
"version": "0.18.1",
"exports": "./mod.ts"
}
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export { Oid, OidTypes } from "./query/oid.ts";
// TODO
// Remove the following reexports after https://doc.deno.land
// supports two level depth exports
export type { OidKey, OidType } from "./query/oid.ts";
export type { OidType, OidValue } from "./query/oid.ts";
export type {
ClientOptions,
ConnectionOptions,
Expand Down
4 changes: 2 additions & 2 deletions query/decode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Oid, OidType, OidTypes } from "./oid.ts";
import { Oid, OidTypes, OidValue } from "./oid.ts";
import { bold, yellow } from "../deps.ts";
import {
decodeBigint,
Expand Down Expand Up @@ -218,7 +218,7 @@ export function decode(
if (controls?.decoders) {
// check if there is a custom decoder by oid (number) or by type name (string)
const decoderFunc = controls.decoders?.[column.typeOid] ||
controls.decoders?.[OidTypes[column.typeOid as OidType]];
controls.decoders?.[OidTypes[column.typeOid as OidValue]];

if (decoderFunc) {
return decoderFunc(strValue, column.typeOid);
Expand Down
13 changes: 7 additions & 6 deletions query/oid.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export type OidKey = keyof typeof Oid;
export type OidType = (typeof Oid)[OidKey];
/** A Postgres Object identifiers (OIDs) type name. */
export type OidType = keyof typeof Oid;
/** A Postgres Object identifiers (OIDs) numeric value. */
export type OidValue = (typeof Oid)[OidType];

/**
* Oid is a map of OidKey to OidType.
* A map of OidType to OidValue.
*/
export const Oid = {
bool: 16,
Expand Down Expand Up @@ -175,11 +177,10 @@ export const Oid = {
} as const;

/**
* OidTypes is a map of OidType to OidKey.
* Used to decode values and avoid search iteration
* A map of OidValue to OidType. Used to decode values and avoid search iteration.
*/
export const OidTypes: {
[key in OidType]: OidKey;
[key in OidValue]: OidType;
} = {
16: "bool",
17: "bytea",
Expand Down