Skip to content

Commit e583d43

Browse files
authored
fix(typegen): Map postgres numeric type to Swift Decimal type (#960)
1 parent 93f0a80 commit e583d43

File tree

5 files changed

+268
-193
lines changed

5 files changed

+268
-193
lines changed

src/server/templates/swift.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ const pgTypeToSwiftType = (
309309
swiftType = 'Float'
310310
} else if (pgType === 'float8') {
311311
swiftType = 'Double'
312+
} else if (['numeric', 'decimal'].includes(pgType)) {
313+
swiftType = 'Decimal'
312314
} else if (pgType === 'uuid') {
313315
swiftType = 'UUID'
314316
} else if (

test/db/00-init.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ CREATE TYPE composite_type_with_array_attribute AS (my_text_array text[]);
88
CREATE TABLE public.users (
99
id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
1010
name text,
11-
status user_status DEFAULT 'ACTIVE'
11+
status user_status DEFAULT 'ACTIVE',
12+
decimal numeric
1213
);
1314
INSERT INTO
1415
public.users (name)

test/lib/tables.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,24 @@ test('list', async () => {
7878
"schema": "public",
7979
"table": "users",
8080
},
81+
{
82+
"check": null,
83+
"comment": null,
84+
"data_type": "numeric",
85+
"default_value": null,
86+
"enums": [],
87+
"format": "numeric",
88+
"identity_generation": null,
89+
"is_generated": false,
90+
"is_identity": false,
91+
"is_nullable": true,
92+
"is_unique": false,
93+
"is_updatable": true,
94+
"name": "decimal",
95+
"ordinal_position": 4,
96+
"schema": "public",
97+
"table": "users",
98+
},
8199
{
82100
"check": null,
83101
"comment": null,

test/server/query.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ test('query', async () => {
1010
expect(res.json()).toMatchInlineSnapshot(`
1111
[
1212
{
13+
"decimal": null,
1314
"id": 1,
1415
"name": "Joe Bloggs",
1516
"status": "ACTIVE",
1617
},
1718
{
19+
"decimal": null,
1820
"id": 2,
1921
"name": "Jane Doe",
2022
"status": "ACTIVE",

0 commit comments

Comments
 (0)