resultSetToMaps method

List<Map<String, dynamic>> resultSetToMaps(
  1. SqlResultSet result, {
  2. bool preserveAliases = false,
})

Convert SqlResultSet to list of maps.

preserveAliases - If true, preserves column aliases as-is without camelCase conversion. Used when relations are present and the RelationDeserializer needs to match aliases.

Implementation

List<Map<String, dynamic>> resultSetToMaps(
  SqlResultSet result, {
  bool preserveAliases = false,
}) {
  if (result.rows.isEmpty) return [];

  final maps = <Map<String, dynamic>>[];

  for (final row in result.rows) {
    final map = <String, dynamic>{};

    for (var i = 0; i < result.columnNames.length; i++) {
      final columnName = result.columnNames[i];
      final value = i < row.length ? row[i] : null;

      // Keep raw DB column names as keys. Generated models deserialize by
      // column name (`@JsonKey(name: '<@map column>')` / manual fromJson
      // reading the DB column), so camelCasing here would desync `@map`-ed
      // columns (e.g. `author_id` -> `authorId`) from what fromJson reads.
      // (`preserveAliases` is retained for API compatibility; both branches
      // now keep the raw column/alias.)
      final key = columnName;

      map[key] = deserializeValue(value, result.columnTypes[i]);
    }

    maps.add(map);
  }

  return maps;
}