You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#656 added support for adding "db:" tags to generated model structs. The db tag is used by sqlx and gorp. GORM takes a similar approach, but uses the "gorm:" tag.
By design, the emit_db_tags option generates the smallest amount of useful tag information. However, if a user is looking to migrate from gorp / sqlx / GORM, it maybe helpful to generate richer tag information.
For sqlx, I don't think there's anything else the db tag can do. For gorp, this would involve setting attribute like primary key, autoincrement, and size:
typePoststruct {
// db tag lets you specify the column name if it differs from the struct fieldIdint64`db:"post_id"`Createdint64Titlestring`db:",size:50"`// Column size set to 50Bodystring`db:"article_body,size:1024"`// Set both column name and size
}
// Example of using tags to alias fields to column names// The 'db' value is the column name//// A hyphen will cause gorp to skip this field, similar to the// Go json package.//// This is equivalent to using the ColMap methods://// table := dbmap.AddTableWithName(Product{}, "product")// table.ColMap("Id").Rename("product_id")// table.ColMap("Price").Rename("unit_price")// table.ColMap("IgnoreMe").SetTransient(true)//// You can optionally declare the field to be a primary key and/or autoincrement//typeProductstruct {
Idint64`db:"product_id, primarykey, autoincrement"`Priceint64`db:"unit_price"`IgnoreMestring`db:"-"`
}
GORM has a huge set of options, as the tags are used instead of DDL statements.
There is currently no plan to work on this until we have a specific user that needs this support and is willing to work closely with us on implementation
Activity