Gorm: Database Postgres

Created on 17 Jun 2016  路  4Comments  路  Source: go-gorm/gorm

I have one database in postgres with many schemas and I would like uses gorm.

do you think it'd be possible to change gorm so that it takes the schemes postgres ?

Most helpful comment

I didn't understand his solution, but I use the method TableName() now.

Example:

type Address struct {
Id uint64 gorm:"primary_key"
CustomerId uint64 sql:"index:idx_addres_customerid""
Street string
}
func (Address) TableName() string {
return "customer.Address"
}

All 4 comments

You should be able to use gorm with this already. You just need to declare your models. You can test by using the db.HasTable(&ModelName{})

@dlundergreen Can you provide an example of this? What if there are two tables in separate schemas that share the same name? I'm not sure how to apply your answer.

I didn't understand his solution, but I use the method TableName() now.

Example:

type Address struct {
Id uint64 gorm:"primary_key"
CustomerId uint64 sql:"index:idx_addres_customerid""
Street string
}
func (Address) TableName() string {
return "customer.Address"
}

yes, the table name method should works.

Was this page helpful?
0 / 5 - 0 ratings