Skip to content

Commit 30b05b3

Browse files
committed
Specify fixed length char
1 parent 2d39389 commit 30b05b3

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

Diff for: src/postgre-data-types.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"serial": "https://www.postgresql.org/docs/9.5/datatype-numeric.html",
1111
"bigserial": "https://www.postgresql.org/docs/9.5/datatype-numeric.html",
1212
"money": "https://www.postgresql.org/docs/9.5/datatype-money.html",
13-
"charachter": "https://www.postgresql.org/docs/9.5/datatype-character.html",
13+
"character": "https://www.postgresql.org/docs/9.5/datatype-character.html",
1414
"char": "https://www.postgresql.org/docs/9.5/datatype-character.html",
1515
"varchar": "https://www.postgresql.org/docs/9.5/datatype-character.html",
1616
"varyingchar": "https://www.postgresql.org/docs/9.5/datatype-character.html",

Diff for: src/repository.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,29 @@ const columnResultDecoder: Decoder<Column[]> = Decoder.array(
2828
column_default: Decoder.optional(Decoder.string),
2929
is_nullable: Decoder.string.map((s) => s === 'YES'),
3030
data_type: Decoder.string,
31-
udt_name: Decoder.string
32-
}).map((res) => ({
33-
table: res.table_name,
34-
name: res.column_name,
35-
default: res.column_default,
36-
isNullable: res.is_nullable,
37-
dataType: res.data_type == 'USER-DEFINED' ? res.udt_name : res.data_type,
38-
}))
31+
udt_name: Decoder.string,
32+
character_maximum_length: Decoder.optional(Decoder.number)
33+
}).map((res) => {
34+
return {
35+
table: res.table_name,
36+
name: res.column_name,
37+
default: res.column_default,
38+
isNullable: res.is_nullable,
39+
dataType: get_datatype(res)
40+
}
41+
})
3942
)
4043

44+
const get_datatype = (res: {udt_name: string, data_type: string, character_maximum_length: number | undefined}) => {
45+
if (res.data_type == 'USER-DEFINED') {
46+
return res.udt_name
47+
}
48+
if (res.data_type == 'character' && res.character_maximum_length) {
49+
return `character (${res.character_maximum_length})`
50+
}
51+
return res.data_type
52+
}
53+
4154
export type View = {
4255
name: string
4356
}

0 commit comments

Comments
 (0)