尝试使用gorp进行 SELECT 时收到以下错误:
No table found for type: Post
这是我的代码的样子:
type Post struct {
Id int64 `db:"post_id"`
CreatedAt int64 `db:"created_at"`
UpdatedAt int64 `db:"updated"`
Title string `db:"title"`
}
var list []*Post
_, err := dbMapper.Select(&list, "SELECT * FROM posts")
if (err != nil) {
fmt.Fprintf(writer, "%s", err)
return
}
for _, item := range list {
fmt.Fprintf(writer, "%s\n", item.Title)
}
我正在添加这样的表:
dbMapper.AddTableWithName(Post{}, "posts").SetKeys(true, "Id")