Create & Init Project...
This commit is contained in:
45
app/interface/main/app-view/dao/manager/BUILD
Normal file
45
app/interface/main/app-view/dao/manager/BUILD
Normal file
@ -0,0 +1,45 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_test",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["dao_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/app-view/conf:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["dao.go"],
|
||||
importpath = "go-common/app/interface/main/app-view/dao/manager",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/app-view/conf:go_default_library",
|
||||
"//app/interface/main/app-view/model/manager:go_default_library",
|
||||
"//library/database/sql:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
52
app/interface/main/app-view/dao/manager/dao.go
Normal file
52
app/interface/main/app-view/dao/manager/dao.go
Normal file
@ -0,0 +1,52 @@
|
||||
package region
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/app-view/conf"
|
||||
"go-common/app/interface/main/app-view/model/manager"
|
||||
xsql "go-common/library/database/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
_relateSQL = "SELECT `id`,`param`,`goto`,`title`,`resource_ids`,`tag_ids`,`archive_ids`,`rec_reason`,`position`,`plat_ver`, `stime`,`etime` FROM app_rcmd_pos WHERE `state`=1"
|
||||
)
|
||||
|
||||
type Dao struct {
|
||||
db *xsql.DB
|
||||
get *xsql.Stmt
|
||||
}
|
||||
|
||||
func New(c *conf.Config) (d *Dao) {
|
||||
d = &Dao{
|
||||
db: xsql.NewMySQL(c.MySQL.Show),
|
||||
}
|
||||
// prepare
|
||||
d.get = d.db.Prepared(_relateSQL)
|
||||
return
|
||||
}
|
||||
|
||||
// Relate get all relate rec.
|
||||
func (d *Dao) Relate(c context.Context) (rs []*manager.Relate, err error) {
|
||||
rows, err := d.get.Query(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
r := &manager.Relate{}
|
||||
if err = rows.Scan(&r.ID, &r.Param, &r.Goto, &r.Title, &r.ResourceIDs, &r.TagIDs, &r.ArchiveIDs, &r.RecReason, &r.Position, &r.PlatVer, &r.STime, &r.ETime); err != nil {
|
||||
return
|
||||
}
|
||||
r.Change()
|
||||
rs = append(rs, r)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Close close db resource.
|
||||
func (d *Dao) Close() {
|
||||
if d.db != nil {
|
||||
d.db.Close()
|
||||
}
|
||||
}
|
37
app/interface/main/app-view/dao/manager/dao_test.go
Normal file
37
app/interface/main/app-view/dao/manager/dao_test.go
Normal file
@ -0,0 +1,37 @@
|
||||
package region
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go-common/app/interface/main/app-view/conf"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func init() {
|
||||
dir, _ := filepath.Abs("../../cmd/app-view-test.toml")
|
||||
flag.Set("conf", dir)
|
||||
conf.Init()
|
||||
d = New(conf.Conf)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
func ctx() context.Context {
|
||||
return context.Background()
|
||||
}
|
||||
|
||||
func TestRelate(t *testing.T) {
|
||||
Convey("get Relate all", t, func() {
|
||||
res, err := d.Relate(ctx())
|
||||
So(err, ShouldBeNil)
|
||||
So(res, ShouldNotBeEmpty)
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user