douxian3828 2015-11-05 13:59
浏览 88
已采纳

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

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"

  • 写回答

2条回答 默认 最新

  • dongmu9253 2016-01-30 05:54
    关注

    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()
    ....
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)