Created
December 10, 2021 04:44
-
-
Save manakuro/f3a8005f971fb1abafe216dc3377a02a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package datastore | |
import ( | |
"golang-clean-architecture-ent-gqlgen/config" | |
"golang-clean-architecture-ent-gqlgen/ent" | |
"entgo.io/ent/dialect" | |
"github.com/go-sql-driver/mysql" | |
) | |
// New returns data source name | |
func New() string { | |
mc := mysql.Config{ | |
User: config.C.Database.User, | |
Passwd: config.C.Database.Password, | |
Net: config.C.Database.Net, | |
Addr: config.C.Database.Addr, | |
DBName: config.C.Database.DBName, | |
AllowNativePasswords: config.C.Database.AllowNativePasswords, | |
Params: map[string]string{ | |
"parseTime": config.C.Database.Params.ParseTime, | |
"charset": config.C.Database.Params.Charset, | |
"loc": config.C.Database.Params.Loc, | |
}, | |
} | |
return mc.FormatDSN() | |
} | |
// NewClient returns an orm client | |
func NewClient() (*ent.Client, error) { | |
var entOptions []ent.Option | |
entOptions = append(entOptions, ent.Debug()) | |
d := New() | |
return ent.Open(dialect.MySQL, d, entOptions...) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment