toField function
SqfEntityFieldType
toField(
- DartObject obj,
- String dbModelName, {
- List<
SqfEntityFieldType> ? defaultColumns,
convert dartObject to SqfEntityFieldType
Implementation
SqfEntityFieldType toField(DartObject obj, String dbModelName,
{List<SqfEntityFieldType>? defaultColumns}) {
final fieldName =
ifExist(obj, 'fieldName') ? getStringValue(obj, 'fieldName') : null;
if (fieldName != null && forbiddenNames.contains(fieldName)) {
throw Exception(
'SQFENTITY ERROR: fieldName: [$fieldName] IS FORBIDDEN. PLEASE CHANGE THE FIELD NAME');
}
final dbType = getTypeValue(obj, 'dbType') as DbType? ?? DbType.text;
if (obj.toString().startsWith('SqfEntityFieldVirtual')) {
return SqfEntityFieldVirtualBase(fieldName!, dbType);
} else if (obj.toString().startsWith('SqfEntityFieldRelationship')) {
final parentTable = toSqfEntityTable(
obj.getField('parentTable')!, dbModelName,
defaultColumns: defaultColumns);
return SqfEntityFieldRelationshipBase(
parentTable, getTypeValue(obj, 'deleteRule') as DeleteRule?)
..defaultValue = getDynamicValue(obj, 'defaultValue')
..minValue = getDynamicValue(obj, 'minValue')
..maxValue = getDynamicValue(obj, 'maxValue')
..fieldName =
ifExist(obj, 'fieldName') ? getStringValue(obj, 'fieldName') : null
..formDropDownTextField = getStringValue(obj, 'formDropDownTextField')
..isPrimaryKeyField = getBoolValue(obj, 'isPrimaryKeyField')
..isNotNull = getBoolValue(obj, 'isNotNull')
..isUnique = getBoolValue(obj, 'isUnique')
..isIndex = getBoolValue(obj, 'isIndex')
..isIndexGroup = getIntValue(obj, 'isIndexGroup')
..checkCondition = getStringValue(obj, 'checkCondition')
..manyToManyTableName = getStringValue(obj, 'manyToManyTableName')
..relationType = getTypeValue(obj, 'relationType') as RelationType?
..collate = getTypeValue(obj, 'collate') as Collate?
..init();
} else {
final SqfEntityFieldType retVal = SqfEntityFieldBase(fieldName!, dbType);
return getFieldProperties(retVal, obj);
}
}