bun icon indicating copy to clipboard operation
bun copied to clipboard

map[string]interface{} with Raw Query

Open gunnrcrakr opened this issue 3 years ago • 2 comments

Why result so weird ?

var m map[string]interface{} err := db.Raw(r.Query).Scan(context.Background(), &m)

map[agent:[48 46 50 53 50 48] agent_commission:[48 46 48 48 48 48] agent_id:5099295 agent_total:[48 46 50 53 50 48] bettime:2022-08-03 22:11:41 +0000 UTC bettime_unix:1659535901 caltime:2022-08-03 22:11:41 +0000 UTC commission:[48 46 48 48 48 48] company:[48 46 48 51 48 48] company_commission:[48 46 48 48 48 48] company_id:1 company_total:[48 46 48 51 48 48] created_at:2022-08-03 22:11:51 +0000 UTC game:[106 108] game_id:25 game_type:[80 97 114 116 121 32 78 105 103 104 116] id:1 master:[48 46 48 48 54 48] master_commission:[48 46 48 48 48 48] master_id:2347398 master_total:[48 46 48 48 54 48] md5:[53 98 99 54 99 52 51 49 56 100 99 48 102 51 99 53 56 97 53 55 53 97 97 102 51 97 52 52 49 102 100 54] ref:[74 73 76 73 45 83 76 79 84 45 48 52 52 95 49 54 53 57 53 51 51 51 55 50 49 55 52 51 54 50 48 55 54] senior:[48 46 48 48 57 48] senior_commission:[48 46 48 48 48 48] senior_id:2268308 senior_total:[48 46 48 48 57 48] subcompany:[48 46 48 48 51 48] subcompany_commission:[48 46 48 48 48 48] subcompany_id:381 subcompany_total:[48 46 48 48 51 48] total:[45 48 46 51 48 48 48] turnover:[48 46 51 48 48 48] up_id:5099295 user_id:48806986 username:[98 114 119 121 103 111 52 101 112 104 113 121 112 119 100 115] valid_amount:[48 46 51 48 48 48] winloss:[45 48 46 51 48 48 48]] Pic: https://cln.sh/Zmt1D3

gunnrcrakr avatar Aug 07 '22 18:08 gunnrcrakr

I guess your database driver returns strings as a []byte. It is not specific to RawQuery. You will get the same result by trying to scan into map[string]any.

vmihailenco avatar Aug 08 '22 07:08 vmihailenco

I guess your database driver returns strings as a []byte. It is not specific to RawQuery. You will get the same result by trying to scan into map[string]any.

I use this

import _ "github.com/go-sql-driver/mysql"

ghost avatar Aug 08 '22 07:08 ghost

@gunnrcrakr mysql driver returns strings as []byte and we can't do much about this. You can try a different driver.

vmihailenco avatar Sep 03 '22 08:09 vmihailenco