Skip to content

Commit

Permalink
count improve
Browse files Browse the repository at this point in the history
  • Loading branch information
fizzday committed Aug 22, 2019
1 parent d169486 commit 10d14e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
4 changes: 3 additions & 1 deletion orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ func (dba *Orm) BuildSql(operType ...string) (a string, b []interface{}, err err
return
}
// 解析字段
if inArray(dba.GetIBinder().GetBindType(), []interface{}{OBJECT_STRUCT, OBJECT_STRUCT_SLICE}) {
// 如果有union操作, 则不需要
if inArray(dba.GetIBinder().GetBindType(), []interface{}{OBJECT_STRUCT, OBJECT_STRUCT_SLICE}) &&
dba.GetUnion()==nil{
dba.fields = getTagName(dba.GetIBinder().GetBindResult(), TAGNAME)
}
if len(operType) == 0 || (len(operType) > 0 && strings.ToLower(operType[0]) == "select") {
Expand Down
22 changes: 12 additions & 10 deletions orm_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ import (
)

func TestOrm_First(t *testing.T) {
db := DB()
var u = Users{}
var err error
//res, err := db.Table(&u).Get()
//if err != nil {
// t.Error(err.Error())
//}
//t.Log(res)
err = db.Table(&u).Select()
res,err := DB().Table("users").First()
if err != nil {
t.Error(err.Error())
}
t.Log(u)
t.Log(res)
}

func TestOrm_Select(t *testing.T) {
Expand Down Expand Up @@ -161,6 +153,16 @@ func TestOrm_Count(t *testing.T) {
t.Log(res, db.LastSql())
}

func TestOrm_Count2(t *testing.T) {
var u Users
var count int64
count, err := DB().Table(&u).Count()
if err != nil {
t.Error(err.Error())
}
t.Log(count)
}

func TestOrm_Chunk(t *testing.T) {
orm := DB()

Expand Down

0 comments on commit 10d14e1

Please sign in to comment.