Skip to content

Commit 69a5a8a

Browse files
fix: allow falsy default values in function (#1533)
Co-authored-by: Shinigami <[email protected]>
1 parent 6505b99 commit 69a5a8a

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

src/utils/formatParams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function formatParam(
2727
options.push(type);
2828
}
2929

30-
if (defaultValue) {
30+
if (defaultValue !== undefined) {
3131
options.push(`DEFAULT ${escapeValue(defaultValue)}`);
3232
}
3333

test/utils/formatParam.spec.ts

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('utils', () => {
6969

7070
expect(actual).toBeTypeOf('string');
7171
expect(actual).toBe(
72-
'(OUT "test" bigint DEFAULT true, INOUT "test2" box)'
72+
'(OUT "test" bigint DEFAULT true, INOUT "test2" box DEFAULT false)'
7373
);
7474
});
7575

@@ -95,7 +95,55 @@ describe('utils', () => {
9595

9696
expect(actual).toBeTypeOf('string');
9797
expect(actual).toBe(
98-
'(integer, bigint, OUT "test" bigint DEFAULT true, VARIADIC "test2" box)'
98+
'(integer, bigint, OUT "test" bigint DEFAULT true, VARIADIC "test2" box DEFAULT false)'
99+
);
100+
});
101+
102+
it('should allow falsy default values', () => {
103+
const actual = formatParams(
104+
[
105+
{
106+
mode: 'OUT',
107+
name: 'test',
108+
type: PgType.BIGINT,
109+
},
110+
{
111+
mode: 'OUT',
112+
name: 'test2',
113+
type: PgType.BOX,
114+
default: undefined,
115+
},
116+
{
117+
mode: 'OUT',
118+
name: 'test3',
119+
type: PgType.BOOL,
120+
default: false,
121+
},
122+
{
123+
mode: 'INOUT',
124+
name: 'test4',
125+
type: PgType.DATE,
126+
default: null,
127+
},
128+
{
129+
mode: 'INOUT',
130+
name: 'test5',
131+
type: PgType.NUMERIC,
132+
default: 0,
133+
},
134+
{
135+
mode: 'INOUT',
136+
name: 'test6',
137+
type: PgType.TEXT,
138+
default: '',
139+
},
140+
],
141+
options1
142+
);
143+
144+
expect(actual).toBeTypeOf('string');
145+
expect(actual).toBe(
146+
'(OUT "test" bigint, OUT "test2" box, OUT "test3" boolean DEFAULT false, INOUT "test4" date DEFAULT NULL, INOUT "test5" numeric DEFAULT 0, INOUT "test6" text DEFAULT $pga$$pga$)'
99147
);
100148
});
101149
});

0 commit comments

Comments
 (0)