Skip to content

Commit 82fee9c

Browse files
authored
Merge pull request #510 from devforth/feature/AdminForth/1326/bool-filters-doesn't-work-
fix: don't throw an error, when user tries to save 1/0 in bool field …
2 parents b4de659 + 5ff76a2 commit 82fee9c

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

adminforth/dataConnectors/baseConnector.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,13 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
308308
return this.setFieldValue(field, null);
309309
}
310310
if (typeof value !== 'boolean') {
311-
throw new Error(`Value is not a boolean. Field ${field.name} with type is ${field.type}, but got value: ${value} with type ${typeof value}`);
311+
const errorMessage = `Value is not a boolean. Field ${field.name} with type is ${field.type}, but got value: ${value} with type ${typeof value}`;
312+
if (value !== 1 && value !== 0) {
313+
throw new Error(errorMessage);
314+
} else {
315+
afLogger.warn(errorMessage);
316+
afLogger.warn(`Ignore this warn, if you are using an sqlite database`);
317+
}
312318
}
313319
return this.setFieldValue(field, value);
314320
}

adminforth/dataConnectors/clickhouse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class ClickhouseConnector extends AdminForthBaseConnector implements IAdminForth
192192
return iso;
193193
}
194194
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
195-
return value === null ? null : (value ? 1 : 0);
195+
return value === null ? null : (value ? true : false);
196196
} else if (field.type == AdminForthDataTypes.JSON) {
197197
// check underline type is text or string
198198
if (field._underlineType.startsWith('String') || field._underlineType.startsWith('FixedString')) {

adminforth/dataConnectors/mysql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class MysqlConnector extends AdminForthBaseConnector implements IAdminForthDataS
225225
}
226226
return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
227227
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
228-
return value === null ? null : (value ? 1 : 0);
228+
return value === null ? null : (value ? true : false);
229229
} else if (field.type == AdminForthDataTypes.JSON) {
230230
if (field._underlineType === 'json') {
231231
return value;

adminforth/dataConnectors/sqlite.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ class SQLiteConnector extends AdminForthBaseConnector implements IAdminForthData
176176
}
177177
return JSON.stringify(value);
178178
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
179+
// SQLite does not have a native boolean type, it uses 0 and 1
180+
// valid only for sqlite
179181
return value === null ? null : (value ? 1 : 0);
180182
} else if (field.type == AdminForthDataTypes.JSON) {
181183
// check underline type is text or string

0 commit comments

Comments
 (0)