toMap method

Map<String, Object?> toMap()

Builds a configuration map suitable for serialization/reuse.

Implementation

Map<String, Object?> toMap() {
  final result = <String, Object?>{};
  if (defaultConnectionName != null) {
    result['default_connection'] = defaultConnectionName;
  }
  if (connections.length > 1) {
    final map = <String, Object?>{};
    for (final entry in connections.entries) {
      map[entry.key] = entry.value.toMap();
    }
    result['connections'] = map;
  } else {
    final only = connections.values.first;
    result.addAll(only.toMap());
  }
  return result;
}