使用Go-Gorp创建表时无法设置列详细信息

huangapple go评论88阅读模式
英文:

Create table using Go-Gorp fails to set column details

问题

尝试使用Gorp-Go ORM包创建表格。成功在MySql中创建了表格,但未能附加列详细信息。

type Data struct {
    id   int    `db:"pid"`
    name string `db:",size:50"`
}

Gorp钩子

Dbm.AddTableWithName(Data{}, "data_test").SetKeys(true, "id")
Dbm.CreateTablesIfNotExists()

Dbm是指向gorp.DbMap的指针。结果表格中的列名为pid和*,size:50*。我尝试过以下方式:

type Data struct {
    id   int    `db:"pid"`
    name string `db:"name:xyz,size:50"`
}

但结果的列名仍为*"name:xyz,size:50"*。

英文:

Trying to create the table using Gorp-Go ORM package. Was able to successfully create the table in MySql but failed to attach column details.

type Data struct {
	id int `db:"pid"`
	name string `db:",size:50"`
}

Gorp hook

Dbm.AddTableWithName(Data{}, "data_test").SetKeys(true, "id")
Dbm.CreateTablesIfNotExists()

Dbm is pointer to gorp.DbMap. The resultant table has pid and ,size:50 has name. Have tried with

   type Data struct {
    	id int `db:"pid"`
    	name string `db:"name:xyz,size:50"`
    }

Still the resultant column name is "name:xyz,size:50"

答案1

得分: 2

根据这个评论,size特性仍然只在dev分支中可用。
你可以通过显式设置maxsize来实现。例如:

dt := Dbm.AddTableWithName(Data{}, "data_test").SetKeys(true, "id")
dt.ColMap("xyz").SetMaxSize(50)
Dbm.CreateTablesIfNotExists()
....
英文:

According to this comment, the size feature is still available in only dev branch.
You can achieve this by explicitly setting maxsize though. Example:

dt := Dbm.AddTableWithName(Data{}, "data_test").SetKeys(true, "id")
dt.ColMap("xyz").SetMaxSize(50)
Dbm.CreateTablesIfNotExists()
....

答案2

得分: 1

我相信列名不需要 "name"。

尝试使用 db:"xyz,size:50"

英文:

I believe the column name doesn't require "name"

Try db:"xyz,size:50"

huangapple
  • 本文由 发表于 2015年11月5日 21:59:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/33546492.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定