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
2 changes: 2 additions & 0 deletions src/pg-structure/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export default class Column extends DbObject {
const { schema: typeSchema, typeName, length, precision, scale } = parseSQLType(this.db, args.sqlType);
this.notNull = args.notNull;
this.type =
this.db.allTypes.getMaybe(args.typeOid, { key: "oid" }) ||
this.db.allTypes.getMaybe(args.typeOid, { key: "arrayOid" }) ||
typeSchema.typesIncludingEntities.getMaybe(typeName, { key: "internalName" }) || typeSchema.typesIncludingEntities.get(typeName);
this.length = length;
this.precision = precision;
Expand Down
19 changes: 18 additions & 1 deletion test/column.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable prefer-destructuring, @typescript-eslint/no-non-null-assertion */
import { Db, Table, View, Column, CompositeType } from "../src/index";
import { Client } from "pg";
import pgStructure, { Db, Table, View, Column, CompositeType, Domain } from "../src/index";
import getDb from "./test-helper/get-db";

let db: Db;
Expand Down Expand Up @@ -65,6 +66,22 @@ describe("Column", () => {
expect(accountTable.get("c").type.name).toBe("circle");
});

it("should resolve an unqualified domain visible through search_path.", async () => {
const client = new Client({ database: "pg-structure-test-main", user: "user", password: "password" });
await client.connect();

try {
await client.query("SET search_path TO other_schema, public");
const searchPathDb = await pgStructure(client);
const domainColumn = searchPathDb.schemas.get("other_schema").tables.get("domain_table").columns.get("name");

expect(domainColumn.type).toBeInstanceOf(Domain);
expect(domainColumn.type.schema.name).toBe("other_schema");
} finally {
await client.end();
}
});

it("should have isSerial.", () => {
expect(idColumn.isSerial).toBe(true);
expect(accountTable.get("c").isSerial).toBe(false);
Expand Down
9 changes: 9 additions & 0 deletions test/test-helper/ddl/main.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ CREATE DOMAIN "cross_schema_domain" AS "udt_composite"[] NOT NULL
CREATE DOMAIN "price" AS Numeric(8,2) DEFAULT 1.2 NOT NULL CHECK (VALUE > 0)
;

CREATE DOMAIN "other_schema"."localised_string" AS jsonb
;

CREATE TABLE "other_schema"."domain_table"
(
"name" "other_schema"."localised_string" NOT NULL
)
;

-- Create functions section -------------------------------------------------

CREATE FUNCTION "trigger_returning_function"()
Expand Down