databse provider
This commit is contained in:
@@ -5,6 +5,14 @@ import (
|
||||
"database/sql"
|
||||
"embed"
|
||||
"fmt"
|
||||
|
||||
"{{.ModuleName}}/database/models"
|
||||
|
||||
"github.com/rogeecn/atom"
|
||||
"go.ipao.vip/atom/container/container"
|
||||
"go.ipao.vip/atom/contracts/contracts"
|
||||
"go.ipao.vip/atom/opt/opt"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
//go:embed migrations/*
|
||||
@@ -31,3 +39,17 @@ func WrapLikeLeft(v string) string {
|
||||
func WrapLikeRight(v string) string {
|
||||
return "%" + v
|
||||
}
|
||||
|
||||
func Provide(...opt.Option) error {
|
||||
return container.Container.Provide(func(db *gorm.DB) contracts.Initial {
|
||||
models.SetDefault(db)
|
||||
return models.Q
|
||||
}, atom.GroupInitial)
|
||||
}
|
||||
|
||||
func DefaultProvider() container.ProviderContainer {
|
||||
return container.ProviderContainer{
|
||||
Provider: Provide,
|
||||
Options: []opt.Option{},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user