toFromMapString method
String
toFromMapString(
)
override
Implementation
@override
String toFromMapString() {
switch (dbType) {
case DbType.bool:
// return 'if (o[\'$fieldName\'] != null) {$fieldName = o[\'$fieldName\'] == 1 || o[\'$fieldName\'] == true;}';
return 'if (o[\'$fieldName\'] != null) {$fieldName = o[\'$fieldName\'].toString() == \'1\' || o[\'$fieldName\'].toString() == \'true\';}'; // https://github.com/hhtokpinar/sqfEntity/issues/170#issuecomment-826160862
case DbType.date:
case DbType.datetime:
return 'if (o[\'$fieldName\'] != null) {$fieldName = int.tryParse(o[\'$fieldName\'].toString()) != null ? DateTime.fromMillisecondsSinceEpoch(int.tryParse(o[\'$fieldName\'].toString())!) : DateTime.tryParse(o[\'$fieldName\'].toString());}';
case DbType.datetimeUtc:
return 'if (o[\'$fieldName\'] != null) {$fieldName = int.tryParse(o[\'$fieldName\'].toString()) != null ? DateTime.fromMillisecondsSinceEpoch(int.tryParse(o[\'$fieldName\'].toString())!, isUtc: true) : DateTime.tryParse(o[\'$fieldName\'].toString());}';
case DbType.real:
return 'if (o[\'$fieldName\'] != null) {$fieldName = double.tryParse(o[\'$fieldName\'].toString());}';
case DbType.integer:
case DbType.numeric:
return 'if (o[\'$fieldName\'] != null) {$fieldName = int.tryParse(o[\'$fieldName\'].toString());}';
case DbType.text:
return 'if (o[\'$fieldName\'] != null) {$fieldName = o[\'$fieldName\'].toString();}';
case DbType.blob:
return 'if(o[\'$fieldName\'] != null) {$fieldName = o[\'$fieldName\'] as ${dartType[dbType!.index].toString()};}';
case DbType.time:
return 'if(o[\'$fieldName\'] != null) {$fieldName = TimeOfDay(hour: int.parse(o[\'$fieldName\'].toString().split(\':\')[0]), minute: int.parse(o[\'$fieldName\'].toString().split(\':\')[1]));}';
default:
// return 'if(o[\'$fieldName\'] != null) {$fieldName = o[\'$fieldName\'] as ${dartType[dbType!.index].toString()};}';
return 'if (o[\'$fieldName\'] != null) {$fieldName = o[\'$fieldName\'].toString();}';
}
}