File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -49,8 +49,8 @@ type SQLBatch struct {
49
49
// newBatchDefaults returns a new SQLBatch with default values
50
50
func newBatchDefaults (opts ... BatchOpt ) * SQLBatch {
51
51
b := & SQLBatch {
52
- fields : nil ,
53
- args : nil ,
52
+ fields : make ([] string , 0 ) ,
53
+ args : make ([] any , 0 ) ,
54
54
db : nil ,
55
55
tagName : patcher .DefaultDbTagName ,
56
56
table : "" ,
@@ -64,10 +64,18 @@ func newBatchDefaults(opts ...BatchOpt) *SQLBatch {
64
64
}
65
65
66
66
func (b * SQLBatch ) Fields () []string {
67
+ if len (b .fields ) == 0 {
68
+ // Default behaviour to return nil if no fields are set
69
+ return nil
70
+ }
67
71
return b .fields
68
72
}
69
73
70
74
func (b * SQLBatch ) Args () []any {
75
+ if len (b .args ) == 0 {
76
+ // Default behaviour to return nil if no args are set
77
+ return nil
78
+ }
71
79
return b .args
72
80
}
73
81
Original file line number Diff line number Diff line change @@ -74,8 +74,8 @@ type SQLPatch struct {
74
74
func newPatchDefaults (opts ... PatchOpt ) * SQLPatch {
75
75
// Default options
76
76
p := & SQLPatch {
77
- fields : nil ,
78
- args : nil ,
77
+ fields : make ([] string , 0 ) ,
78
+ args : make ([] any , 0 ) ,
79
79
db : nil ,
80
80
tagName : DefaultDbTagName ,
81
81
table : "" ,
@@ -97,10 +97,18 @@ func newPatchDefaults(opts ...PatchOpt) *SQLPatch {
97
97
}
98
98
99
99
func (s * SQLPatch ) Fields () []string {
100
+ if len (s .fields ) == 0 {
101
+ // Default behaviour is to return nil if there are no fields
102
+ return nil
103
+ }
100
104
return s .fields
101
105
}
102
106
103
107
func (s * SQLPatch ) Args () []any {
108
+ if len (s .args ) == 0 {
109
+ // Default behaviour is to return nil if there are no args
110
+ return nil
111
+ }
104
112
return s .args
105
113
}
106
114
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ func WithWhere(where Wherer) PatchOpt {
37
37
}
38
38
fwSQL , fwArgs := where .Where ()
39
39
if fwArgs == nil {
40
- fwArgs = []any {}
40
+ fwArgs = make ( []any , 0 )
41
41
}
42
42
wtStr := WhereTypeAnd // default to AND
43
43
wt , ok := where .(WhereTyper )
@@ -59,7 +59,7 @@ func WithJoin(join Joiner) PatchOpt {
59
59
}
60
60
fjSQL , fjArgs := join .Join ()
61
61
if fjArgs == nil {
62
- fjArgs = []any {}
62
+ fjArgs = make ( []any , 0 )
63
63
}
64
64
s .joinSql .WriteString (strings .TrimSpace (fjSQL ))
65
65
s .joinSql .WriteString ("\n " )
You can’t perform that action at this time.
0 commit comments