You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
kratos/tool/kratos-gen-project/templates/all/internal/dao/db.go.tmpl

30 lines
600 B

package dao
import (
"context"
"{{.ModPrefix}}{{.Name}}/internal/model"
"github.com/go-kratos/kratos/pkg/conf/paladin"
"github.com/go-kratos/kratos/pkg/database/sql"
)
func NewDB() (db *sql.DB, cf func(), err error) {
var (
cfg sql.Config
ct paladin.TOML
)
if err = paladin.Get("db.toml").Unmarshal(&ct); err != nil {
return
}
if err = ct.Get("Client").UnmarshalTOML(&cfg); err != nil {
return
}
db = sql.NewMySQL(&cfg)
cf = func() {db.Close()}
return
}
func (d *dao) RawArticle(ctx context.Context, id int64) (art *model.Article, err error) {
// get data from db
return
}