mysql: simplify `Result.maps`

pull/4743/head
Don Alfons Nisnoni 2020-05-06 06:10:10 +08:00 committed by GitHub
parent c1f224640f
commit 67a50b5b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 10 deletions

View File

@ -57,24 +57,21 @@ pub fn (r Result) rows() []Row {
return rows
}
// maps return rows with `map` of columns instead `array` of columns
pub fn (r Result) maps() []map[string]string {
mut array_map := []map[string]string{}
rows := r.rows()
fields := r.fetch_fields()
for i in 0..rows.len {
array_map << r.create_map_value(rows[i])
mut map_val := map[string]string
for j in 0..fields.len {
map_val[fields[j].name] = rows[i].vals[j]
}
array_map << map_val
}
return array_map
}
fn (r Result) create_map_value(row Row) map[string]string {
mut map_ := map[string]string
fields := r.fetch_fields()
for i in 0..fields.len {
map_[fields[i].name] = row.vals[i]
}
return map_
}
pub fn (r Result) fetch_fields() []Field {
mut fields := []Field{}
nr_cols := r.num_fields()