mysqlgogorp

Create table using Go-Gorp fails to set column details


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"


Solution

  • 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()
    ....