26 lines
395 B
Go
26 lines
395 B
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/fx"
|
|
|
|
"epic-ent/internal/config"
|
|
"epic-ent/internal/ent"
|
|
)
|
|
|
|
func NewEntClient(lc fx.Lifecycle, cfg *config.Config) (*ent.Client, error) {
|
|
client, err := ent.Open("mysql", cfg.MySQL.DSN)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
lc.Append(fx.Hook{
|
|
OnStop: func(ctx context.Context) error {
|
|
return client.Close()
|
|
},
|
|
})
|
|
|
|
return client, nil
|
|
}
|