@@ -3,20 +3,14 @@ package session
3
3
import (
4
4
"geeorm/clause"
5
5
"reflect"
6
- "strings"
7
6
)
8
7
9
8
// Create one or more records in database
10
9
func (s * Session ) Create (values ... interface {}) (int64 , error ) {
11
- var flag bool
12
10
recordValues := make ([]interface {}, 0 )
13
11
for _ , value := range values {
14
12
table := s .RefTable (value )
15
- if ! flag {
16
- flag = true
17
- fieldSQL := strings .Join (table .FieldNames , ", " )
18
- s .clause .Set (clause .INSERT , table .TableName , fieldSQL )
19
- }
13
+ s .clause .Set (clause .INSERT , table .TableName , table .FieldNames )
20
14
recordValues = append (recordValues , table .Values (value ))
21
15
}
22
16
@@ -34,9 +28,7 @@ func (s *Session) Create(values ...interface{}) (int64, error) {
34
28
func (s * Session ) First (value interface {}) error {
35
29
table := s .RefTable (value )
36
30
37
- fieldSQL := strings .Join (table .FieldNames , ", " )
38
-
39
- s .clause .Set (clause .SELECT , table .TableName , fieldSQL )
31
+ s .clause .Set (clause .SELECT , table .TableName , table .FieldNames )
40
32
s .clause .Set (clause .LIMIT , 1 )
41
33
42
34
sql , vars := s .clause .Build ([]clause.Type {clause .SELECT , clause .LIMIT })
@@ -57,8 +49,7 @@ func (s *Session) Find(values interface{}) error {
57
49
destType := destSlice .Type ().Elem ()
58
50
table := s .RefTable (reflect .New (destType ).Elem ().Interface ())
59
51
60
- fieldSQL := strings .Join (table .FieldNames , ", " )
61
- s .clause .Set (clause .SELECT , table .TableName , fieldSQL )
52
+ s .clause .Set (clause .SELECT , table .TableName , table .FieldNames )
62
53
sql , vars := s .clause .Build ([]clause.Type {clause .SELECT })
63
54
rows , err := s .Raw (sql , vars ... ).QueryRows ()
64
55
if err != nil {
@@ -76,8 +67,5 @@ func (s *Session) Find(values interface{}) error {
76
67
}
77
68
destSlice .Set (reflect .Append (destSlice , dest ))
78
69
}
79
- if err := rows .Close (); err != nil {
80
- return err
81
- }
82
- return nil
70
+ return rows .Close ()
83
71
}
0 commit comments