Gorp Insertion带有嵌入式结构

时间:2017-03-16 16:55:22

标签: go gorp

我是Gorp和Golang的新手。

https://github.com/go-gorp/gorp

我有一个类似

的mysql表
Table: product

Column: id(int), name(string), category1(string), category2(string)

我创建了一个嵌入式结构,如

type (
    Product struct {
        Id       int
        Name     Names `db:"name"`
        Categories Categories

    }

    Categories struct {
        Category1 string `db:"category1"`
        Category2 string `db:"category2"`
    }
)

我执行了以下脚本

.......
product := &Product{-1,"foobar", Categories{"sample1", "sample2"}}
err := dbmap.Insert(product)
fmt.Println(err)

但是我收到了以下错误消息

converting Exec argument $2 type: unsupported type main.Categories, a struct

我以为我遵循了Struct嵌入手册。

https://github.com/go-gorp/gorp#struct-embedding

请帮助我理解为什么我仍然会收到此错误。

0 个答案:

没有答案