Skip to content

Commit d9d6d60

Browse files
committed
enhance boolean handling to support null values across data connectors
1 parent 07382ab commit d9d6d60

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

adminforth/dataConnectors/clickhouse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class ClickhouseConnector extends AdminForthBaseConnector implements IAdminForth
107107
}
108108
return dayjs(value).toISOString().split('T')[0];
109109
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
110-
return !!value;
110+
return value === null ? null : !!value;
111111
} else if (field.type == AdminForthDataTypes.JSON) {
112112
if (field._underlineType.startsWith('String') || field._underlineType.startsWith('FixedString')) {
113113
try {
@@ -138,7 +138,7 @@ class ClickhouseConnector extends AdminForthBaseConnector implements IAdminForth
138138
return iso;
139139
}
140140
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
141-
return value ? 1 : 0;
141+
return value === null ? null : (value ? 1 : 0);
142142
} else if (field.type == AdminForthDataTypes.JSON) {
143143
// check underline type is text or string
144144
if (field._underlineType.startsWith('String') || field._underlineType.startsWith('FixedString')) {

adminforth/dataConnectors/mysql.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class MysqlConnector extends AdminForthBaseConnector implements IAdminForthDataS
130130
} else if (field.type == AdminForthDataTypes.TIME) {
131131
return value || null;
132132
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
133-
return !!value;
133+
return value === null ? null : !!value;
134134
} else if (field.type == AdminForthDataTypes.JSON) {
135135
if (typeof value === 'string') {
136136
try {
@@ -158,7 +158,7 @@ class MysqlConnector extends AdminForthBaseConnector implements IAdminForthDataS
158158
}
159159
return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
160160
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
161-
return value ? 1 : 0;
161+
return value === null ? null : (value ? 1 : 0);
162162
} else if (field.type == AdminForthDataTypes.JSON) {
163163
if (field._underlineType === 'json') {
164164
return value;

adminforth/dataConnectors/postgres.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ class PostgresConnector extends AdminForthBaseConnector implements IAdminForthDa
157157
return dayjs(value).toISOString().split('T')[0];
158158
}
159159

160+
if (field.type == AdminForthDataTypes.BOOLEAN) {
161+
return value === null ? null : !!value;
162+
}
163+
160164
if (field.type == AdminForthDataTypes.JSON) {
161165
if (typeof value == 'string') {
162166
try {
@@ -188,7 +192,7 @@ class PostgresConnector extends AdminForthBaseConnector implements IAdminForthDa
188192
return dayjs(value).toISOString();
189193
}
190194
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
191-
return value ? 1 : 0;
195+
return value === null ? null : (value ? 1 : 0);
192196
} else if (field.type == AdminForthDataTypes.JSON) {
193197
if (field._underlineType == 'json') {
194198
return value;

0 commit comments

Comments
 (0)