Skip to content

Commit 90feac5

Browse files
committed
fix: improve JSON handling in getFieldValue and setFieldValue SQLite methods
1 parent 118fbe0 commit 90feac5

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

adminforth/dataConnectors/sqlite.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,14 @@ class SQLiteConnector extends AdminForthBaseConnector implements IAdminForthData
155155
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
156156
return value === null ? null : !!value;
157157
} else if (field.type == AdminForthDataTypes.JSON) {
158-
if (field._underlineType == 'text' || field._underlineType == 'varchar') {
158+
if (typeof value === 'string') {
159159
try {
160160
return JSON.parse(value);
161161
} catch (e) {
162162
return {'error': `Failed to parse JSON: ${e.message}`}
163163
}
164-
} else {
165-
afLogger.warn(`AdminForth: JSON field is not a string/text but ${field._underlineType}, this is not supported yet`);
166164
}
167165
}
168-
169166
return value;
170167
}
171168

@@ -192,12 +189,10 @@ class SQLiteConnector extends AdminForthBaseConnector implements IAdminForthData
192189
} else if (field.type == AdminForthDataTypes.BOOLEAN) {
193190
return value === null ? null : (value ? 1 : 0);
194191
} else if (field.type == AdminForthDataTypes.JSON) {
195-
// check underline type is text or string
196-
if (field._underlineType == 'text' || field._underlineType == 'varchar') {
197-
return JSON.stringify(value);
198-
} else {
199-
afLogger.warn(`AdminForth: JSON field is not a string/text but ${field._underlineType}, this is not supported yet`);
192+
if (value === null || value === undefined) {
193+
return null;
200194
}
195+
return typeof value === 'string' ? value : JSON.stringify(value);
201196
}
202197

203198
return value;

0 commit comments

Comments
 (0)