pastebin/internal/repositories/sqlite.go
2023-09-30 21:47:59 +08:00

31 lines
577 B
Go

package repositories
import (
"gitter.top/drivers/sdbc"
"pastebin/config"
modelv1 "pastebin/model/v1"
"time"
)
var (
driver *sdbc.Driver
pastebinOperator sdbc.Operator
)
func GetPastebin() sdbc.Operator {
if driver == nil {
cfg := config.Get()
driver = sdbc.NewSDBC(&sdbc.Config{
Dbname: cfg.DBConfig.Dbname,
MaxIdleConn: 20,
MaxOpenConn: 200,
MaxLifetime: time.Hour,
Debug: cfg.DBConfig.Debug,
})
}
if pastebinOperator == nil {
pastebinOperator = driver.BindModel(&modelv1.ModelPastebin{})
}
return pastebinOperator
}