src.dualinventive.com/go/lib/database/gorm.go

14 lines
392 B
Go

package database
import (
"github.com/jinzhu/gorm"
)
// SetTablePrefix prefixes all the tables with the given prefix.
// If prefix is "myapplication_" and the struct name is "User", the table name will be: "myapplication_users"
func SetTablePrefix(prefix string) {
gorm.DefaultTableNameHandler = func(db *gorm.DB, defaultTableName string) string {
return prefix + defaultTableName
}
}