From 20326bfb62eee51784db54355defdc0d6a3ac476 Mon Sep 17 00:00:00 2001 From: Simon Bugert Date: Tue, 4 Dec 2018 13:27:13 +0100 Subject: [PATCH] Add mapping for custom enum array types in postgres --- src/schemaPostgres.ts | 3 +++ test/expected/postgres/osm.ts | 2 ++ test/fixture/postgres/osm.sql | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/schemaPostgres.ts b/src/schemaPostgres.ts index 2acceb9..c9f24e4 100644 --- a/src/schemaPostgres.ts +++ b/src/schemaPostgres.ts @@ -83,6 +83,9 @@ export class PostgresDatabase implements Database { if (customTypes.indexOf(column.udtName) !== -1) { column.tsType = options.transformTypeName(column.udtName) return column + } else if(customTypes.map(type => `_${type}`).indexOf(column.udtName) !== -1) { + column.tsType = `Array<${options.transformTypeName(column.udtName)}>` + return column } else { console.log(`Type [${column.udtName} has been mapped to [any] because no specific type has been found.`) column.tsType = 'any' diff --git a/test/expected/postgres/osm.ts b/test/expected/postgres/osm.ts index 8c59518..58f8aad 100644 --- a/test/expected/postgres/osm.ts +++ b/test/expected/postgres/osm.ts @@ -65,6 +65,7 @@ export namespace usersFields { export type json_array_col = Array | null; export type jsonb_array_col = Array | null; export type timestamptz_array_col = Array | null; + export type formats = Array | null; } @@ -130,4 +131,5 @@ export interface users { json_array_col: usersFields.json_array_col; jsonb_array_col: usersFields.jsonb_array_col; timestamptz_array_col: usersFields.timestamptz_array_col; + formats: usersFields.formats; } diff --git a/test/fixture/postgres/osm.sql b/test/fixture/postgres/osm.sql index 0dc7ec4..9857f32 100644 --- a/test/fixture/postgres/osm.sql +++ b/test/fixture/postgres/osm.sql @@ -77,5 +77,6 @@ CREATE TABLE users ( name_type_col name, json_array_col json[], jsonb_array_col jsonb[], - timestamptz_array_col timestamptz[] + timestamptz_array_col timestamptz[], + formats format_enum[] );