Closed as not planned
Description
what should i fix this error?
- model
type ScriptCategory struct {
bun.BaseModel `bun:"script_category,alias:sc" json:"-"`
Id int64 `bun:"id,pk" json:"id"`
Name string `bun:"name" json:"name"`
Sort float32 `bun:"sort" json:"sort"`
BaseFields `json:"-"`
}
- sql
CREATE TABLE `script_category` (
`id` bigint(20) NOT NULL,
`name` varchar(255) NOT NULL DEFAULT '',
`sort` float NOT NULL DEFAULT '0' ,
`created_at` int(11) unsigned NOT NULL DEFAULT '0' ,
`updated_at` int(11) unsigned NOT NULL DEFAULT '0' ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ;
- function
func QueryCategory(ctx context.Context, db *bun.DB) (list []model.ScriptCategory, err error) {
err = db.NewSelect().Model(&model.ScriptCategory{}).
ColumnExpr("sc.id, sc.name, sc.sort").
Order("sort asc").
Scan(ctx, &list)
if err != nil {
err = fmt.Errorf("NewSelect ScriptCategory: %v", err)
return
}
return
}
- error log
[bun] 10:34:57.703 SELECT 19.081ms SELECT sc.id, sc.name, sc.sort FROM `script_category` AS `sc` ORDER BY `sort` asc *fmt.wrapError: sql: Scan error on column index 2, name "sort": bun: can't scan 1 (float32) into float32