Skip to content

Commit

Permalink
Update OID type (#463)
Browse files Browse the repository at this point in the history
* chore: update oid types

* chore: update package version
  • Loading branch information
bombillazo committed Feb 12, 2024
1 parent c9d874e commit 37f41f5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
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

3 comments on commit 37f41f5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No typecheck tests failure

This error was most likely caused by incorrect type stripping from the SWC crate

Please report the following failure to https://github.com/denoland/deno with a reproduction of the current commit

Failure log

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No typecheck tests failure

This error was most likely caused by incorrect type stripping from the SWC crate

Please report the following failure to https://github.com/denoland/deno with a reproduction of the current commit

Failure log

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No typecheck tests failure

This error was most likely caused by incorrect type stripping from the SWC crate

Please report the following failure to https://github.com/denoland/deno with a reproduction of the current commit

Failure log

Please sign in to comment.