Skip to content

Commit 10d14e1

Browse files
committed
count improve
1 parent d169486 commit 10d14e1

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

orm.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ func (dba *Orm) BuildSql(operType ...string) (a string, b []interface{}, err err
265265
return
266266
}
267267
// 解析字段
268-
if inArray(dba.GetIBinder().GetBindType(), []interface{}{OBJECT_STRUCT, OBJECT_STRUCT_SLICE}) {
268+
// 如果有union操作, 则不需要
269+
if inArray(dba.GetIBinder().GetBindType(), []interface{}{OBJECT_STRUCT, OBJECT_STRUCT_SLICE}) &&
270+
dba.GetUnion()==nil{
269271
dba.fields = getTagName(dba.GetIBinder().GetBindResult(), TAGNAME)
270272
}
271273
if len(operType) == 0 || (len(operType) > 0 && strings.ToLower(operType[0]) == "select") {

orm_query_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,11 @@ import (
77
)
88

99
func TestOrm_First(t *testing.T) {
10-
db := DB()
11-
var u = Users{}
12-
var err error
13-
//res, err := db.Table(&u).Get()
14-
//if err != nil {
15-
// t.Error(err.Error())
16-
//}
17-
//t.Log(res)
18-
err = db.Table(&u).Select()
10+
res,err := DB().Table("users").First()
1911
if err != nil {
2012
t.Error(err.Error())
2113
}
22-
t.Log(u)
14+
t.Log(res)
2315
}
2416

2517
func TestOrm_Select(t *testing.T) {
@@ -161,6 +153,16 @@ func TestOrm_Count(t *testing.T) {
161153
t.Log(res, db.LastSql())
162154
}
163155

156+
func TestOrm_Count2(t *testing.T) {
157+
var u Users
158+
var count int64
159+
count, err := DB().Table(&u).Count()
160+
if err != nil {
161+
t.Error(err.Error())
162+
}
163+
t.Log(count)
164+
}
165+
164166
func TestOrm_Chunk(t *testing.T) {
165167
orm := DB()
166168

0 commit comments

Comments
 (0)