Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion adminforth/dataConnectors/baseConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,13 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
return this.setFieldValue(field, null);
}
if (typeof value !== 'boolean') {
throw new Error(`Value is not a boolean. Field ${field.name} with type is ${field.type}, but got value: ${value} with type ${typeof value}`);
const errorMessage = `Value is not a boolean. Field ${field.name} with type is ${field.type}, but got value: ${value} with type ${typeof value}`;
if (value !== 1 && value !== 0) {
throw new Error(errorMessage);
} else {
afLogger.warn(errorMessage);
afLogger.warn(`Ignore this warn, if you are using an sqlite database`);
}
}
return this.setFieldValue(field, value);
}
Expand Down
2 changes: 1 addition & 1 deletion adminforth/dataConnectors/clickhouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class ClickhouseConnector extends AdminForthBaseConnector implements IAdminForth
return iso;
}
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
return value === null ? null : (value ? 1 : 0);
return value === null ? null : (value ? true : false);
} else if (field.type == AdminForthDataTypes.JSON) {
// check underline type is text or string
if (field._underlineType.startsWith('String') || field._underlineType.startsWith('FixedString')) {
Expand Down
2 changes: 1 addition & 1 deletion adminforth/dataConnectors/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class MysqlConnector extends AdminForthBaseConnector implements IAdminForthDataS
}
return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
return value === null ? null : (value ? 1 : 0);
return value === null ? null : (value ? true : false);
} else if (field.type == AdminForthDataTypes.JSON) {
if (field._underlineType === 'json') {
return value;
Expand Down
2 changes: 2 additions & 0 deletions adminforth/dataConnectors/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ class SQLiteConnector extends AdminForthBaseConnector implements IAdminForthData
}
return JSON.stringify(value);
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
// SQLite does not have a native boolean type, it uses 0 and 1
// valid only for sqlite
return value === null ? null : (value ? 1 : 0);
} else if (field.type == AdminForthDataTypes.JSON) {
// check underline type is text or string
Expand Down