我有一個用戶模型,目前只有一行。我想指望整個用戶表中的行數,這裏是我的代碼:計數返回錯誤結果
var count int64
db.Model(&models.User{}).Count(count)
fmt.Println(count)
我期待但打印。 什麼是使用gorm打印表格中的行數的正確方法?
更新:我的用戶模型:
package models
import "github.com/jinzhu/gorm"
type User struct {
gorm.Model
Name string
Password string
Admin bool
}
我們不知道'db.Model','models.User'和'Count'是他們做什麼或他們做了什麼。請提供[最小,完整和可驗證示例](https://stackoverflow.com/help/mcve)。 – Marc