Create table using Go-Gorp fails to set column details

216 views Asked by At

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

There are 2 answers

0
Fallen On BEST ANSWER

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()
....
0
Misrab On

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

Try db:"xyz,size:50"