convertChangeData function Null safety

Map<String, dynamic> convertChangeData(
  1. List<Map<String, dynamic>> columns,
  2. Map<String, dynamic> records,
  3. {List<String>? skipTypes}
)

Takes an array of columns and an object of string values then converts each string value to its mapped type.

columns All of the columns records The map of string values skipTypes The array of types that should not be converted

convertChangeData([{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}], {first_name: 'Paul', age:'33'}, {})
=> { first_name: 'Paul', age: 33 }

Implementation

Map<String, dynamic> convertChangeData(
  List<Map<String, dynamic>> columns,
  Map<String, dynamic> records, {
  List<String>? skipTypes,
}) {
  final result = <String, dynamic>{};
  final _skipTypes = skipTypes ?? [];
  final parsedColumns = <PostgresColumn>[];

  for (final element in columns) {
    final name = element['name'] as String?;
    final type = element['type'] as String?;
    if (name != null && type != null) {
      parsedColumns.add(PostgresColumn(name, type));
    }
  }

  records.forEach((key, value) {
    result[key] = convertColumn(key, parsedColumns, records, _skipTypes);
  });
  return result;
}