mysql1_dart icon indicating copy to clipboard operation
mysql1_dart copied to clipboard

add a method that returns the data as a map list just like the "postgres" package

Open insinfo opened this issue 3 years ago • 0 comments

add a method that returns the data as a map list just like the "postgres" package, I thought of an implementation like this, maybe an extension of the Results class

extension Mysql1ToMapsExtension on Results {
  Future<List<Map<String, dynamic>>> asMaps() async {
    var listMap = <Map<String, dynamic>>[];
    var fields = this.fields;
    await this.forEach((ResultRow row) {
      var map = <String, dynamic>{};
      for (var i = 0; i < row.length; i++) {
        map.addAll({fields[i].name: row[i]});
      }
      listMap.add(map);
    });
    return listMap;
  }
}

insinfo avatar Feb 09 '22 14:02 insinfo