🎉: init project
This commit is contained in:
38
internal/database/db/client.go
Normal file
38
internal/database/db/client.go
Normal file
@ -0,0 +1,38 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"ultone/internal/opt"
|
||||
"ultone/internal/tool"
|
||||
)
|
||||
|
||||
var (
|
||||
cli = &client{}
|
||||
)
|
||||
|
||||
type client struct {
|
||||
cli *gorm.DB
|
||||
ttype string
|
||||
}
|
||||
|
||||
func Type() string {
|
||||
return cli.ttype
|
||||
}
|
||||
|
||||
func New(ctxs ...context.Context) *gorm.DB {
|
||||
var ctx context.Context
|
||||
if len(ctxs) > 0 && ctxs[0] != nil {
|
||||
ctx = ctxs[0]
|
||||
} else {
|
||||
ctx = tool.Timeout(30)
|
||||
}
|
||||
|
||||
session := cli.cli.Session(&gorm.Session{Context: ctx})
|
||||
|
||||
if opt.Debug {
|
||||
session = session.Debug()
|
||||
}
|
||||
|
||||
return session
|
||||
}
|
Reference in New Issue
Block a user