Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

golang 使用go-sql-driver/mysql 查总条数

需求是分页
链接mysql用的 go-sql-driver/mysql
我想拿到符合条件数据的总条数,但我没找到对应的方法
请教大佬们有啥方法


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

rows, err := db.Query("SELECT * FROM userinfo LIMIT 0,5")
原生SQL分页就可以了,总条数就用count(*)或者count(1)加上query条件。
但,你为什么不用orm去做?
gorm: https://github.com/go-gorm/gorm
xorm: https://github.com/go-xorm/xorm


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...