Gorm native sql gets the number of returned messages

I would like to ask you a question about gorm. How does the data queried by raw know the total number of entries before LIMIT, which is used for pagination
db.Db.Offset (offset) .Limit (limit) .Raw ("sql"). Scan (& result.SubjectListResult). Count (& result.Count)

count can"t get it at the end
there is only one line of scan prompt in front of scan

the temporary solution now is to SELECT count (1) check again

Oct.29,2021

r := db.Db.Offset(offset).Limit(limit).Raw("sql").Scan(&result.SubjectListResult).RowsAffected

r is the number of records returned by your query. Besides, isn't your result.SubjectListResult just a slice, just len (result.SubjectListResult) directly?

Menu