File tree 2 files changed +34
-2
lines changed
2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -105,10 +105,20 @@ func (t *Table) Insert() (stmt string, names []string) {
105
105
106
106
// Update returns update by primary key statement.
107
107
func (t * Table ) Update (columns ... string ) (stmt string , names []string ) {
108
- return qb .Update (t .metadata .Name ).Set (columns ... ).Where (t .primaryKeyCmp ... ).ToCql ()
108
+ return t .UpdateBuilder (columns ... ).ToCql ()
109
+ }
110
+
111
+ // UpdateBuilder returns a builder initialised to update by primary key statement.
112
+ func (t * Table ) UpdateBuilder (columns ... string ) * qb.UpdateBuilder {
113
+ return qb .Update (t .metadata .Name ).Set (columns ... ).Where (t .primaryKeyCmp ... )
109
114
}
110
115
111
116
// Delete returns delete by primary key statement.
112
117
func (t * Table ) Delete (columns ... string ) (stmt string , names []string ) {
113
- return qb .Delete (t .metadata .Name ).Columns (columns ... ).Where (t .primaryKeyCmp ... ).ToCql ()
118
+ return t .DeleteBuilder (columns ... ).ToCql ()
119
+ }
120
+
121
+ // DeleteBuilder returns a builder initialised to delete by primary key statement.
122
+ func (t * Table ) DeleteBuilder (columns ... string ) * qb.DeleteBuilder {
123
+ return qb .Delete (t .metadata .Name ).Columns (columns ... ).Where (t .primaryKeyCmp ... )
114
124
}
Original file line number Diff line number Diff line change @@ -171,6 +171,17 @@ func TestTableUpdate(t *testing.T) {
171
171
t .Error (diff , names )
172
172
}
173
173
}
174
+
175
+ // run UpdateBuilder on the same data set
176
+ for _ , test := range table {
177
+ stmt , names := New (test .M ).UpdateBuilder (test .C ... ).ToCql ()
178
+ if diff := cmp .Diff (test .S , stmt ); diff != "" {
179
+ t .Error (diff )
180
+ }
181
+ if diff := cmp .Diff (test .N , names ); diff != "" {
182
+ t .Error (diff , names )
183
+ }
184
+ }
174
185
}
175
186
176
187
func TestTableDelete (t * testing.T ) {
@@ -220,6 +231,17 @@ func TestTableDelete(t *testing.T) {
220
231
t .Error (diff , names )
221
232
}
222
233
}
234
+
235
+ // run DeleteBuilder on the same data set
236
+ for _ , test := range table {
237
+ stmt , names := New (test .M ).DeleteBuilder (test .C ... ).ToCql ()
238
+ if diff := cmp .Diff (test .S , stmt ); diff != "" {
239
+ t .Error (diff )
240
+ }
241
+ if diff := cmp .Diff (test .N , names ); diff != "" {
242
+ t .Error (diff , names )
243
+ }
244
+ }
223
245
}
224
246
225
247
func TestTableConcurrentUsage (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments