convertColumn function
dynamic
convertColumn()
Converts the value of an individual column.
columnName
The column that you want to convert
columns
All of the columns
records
The map of string values
skipTypes
An array of types that should not be converted
convertColumn('age', [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], ['Paul', '33'], [])
=> 33
convertColumn('age', [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], ['Paul', '33'], ['int4'])
=> "33"
Implementation
dynamic convertColumn(
String columnName,
List<PostgresColumn> columns,
Map<String, dynamic> record,
List<String> skipTypes,
) {
final column = columns.firstWhereOrNull((x) => x.name == columnName);
final columnValue = record[columnName];
if (column != null && !skipTypes.contains(column.type)) {
return convertCell(column.type, columnValue);
}
return noop(columnValue);
}