2

我想在使用 Postgres 的应用程序中声明我的 Go 模型。

我正在经历go-pg。及其相关标签。

然而,在有关模型定义的文档中,似乎没有标签(?)用于字段(pk)自动递增(即SERIALpostgressql 定义中的对应部分,例如如下

CREATE TABLE IF NOT EXISTS "day" (
  "id" SERIAL PRIMARY KEY,

如何在go模型结构中声明这样一个选项?

4

1 回答 1

1

我没有使用过go-pg,但据我了解,通过文档ID(或Id)字段自动解析为序列键和主键,因此您无需指定。

模型定义文档

type Genre struct {
    Id     int // Id is automatically detected as primary key
}
type Author struct {
    ID    int     // both "Id" and "ID" are detected as primary key
}
于 2020-01-12T14:47:55.170 回答