Skip to content

Commit af068de

Browse files
committed
Remove IF.
1 parent a4ec9c8 commit af068de

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

update.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const (
1717
updateMarkerAfterWhere
1818
updateMarkerAfterOrderBy
1919
updateMarkerAfterLimit
20-
updateMarkerAfterIf
2120
)
2221

2322
// NewUpdateBuilder creates a new UPDATE builder.
@@ -47,7 +46,6 @@ type UpdateBuilder struct {
4746
orderByCols []string
4847
order string
4948
limit int
50-
ifExprs []string
5149

5250
args *Args
5351

@@ -159,13 +157,6 @@ func (ub *UpdateBuilder) Limit(limit int) *UpdateBuilder {
159157
return ub
160158
}
161159

162-
// If sets IF expressions for UPDATE.
163-
func (ub *UpdateBuilder) If(andExpr ...string) *UpdateBuilder {
164-
ub.ifExprs = append(ub.ifExprs, andExpr...)
165-
ub.marker = updateMarkerAfterIf
166-
return ub
167-
}
168-
169160
// String returns the compiled UPDATE string.
170161
func (ub *UpdateBuilder) String() string {
171162
s, _ := ub.Build()
@@ -216,12 +207,6 @@ func (ub *UpdateBuilder) BuildWithFlavor(flavor Flavor, initialArg ...interface{
216207
ub.injection.WriteTo(buf, updateMarkerAfterLimit)
217208
}
218209

219-
if len(ub.ifExprs) > 0 {
220-
buf.WriteString(" IF ")
221-
buf.WriteString(strings.Join(ub.ifExprs, " AND "))
222-
ub.injection.WriteTo(buf, updateMarkerAfterIf)
223-
}
224-
225210
return ub.args.CompileWithFlavor(buf.String(), flavor, initialArg...)
226211
}
227212

update_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,14 @@ func ExampleUpdateBuilder() {
4444
"modified_at > created_at + "+ub.Var(86400), // It's allowed to write arbitrary SQL.
4545
)
4646
ub.OrderBy("id").Asc()
47-
ub.If(
48-
ub.E("type", "sys"),
49-
ub.E("ready", true),
50-
)
5147

5248
sql, args := ub.Build()
5349
fmt.Println(sql)
5450
fmt.Println(args)
5551

5652
// Output:
57-
// UPDATE demo.user SET type = ?, credit = credit + 1, modified_at = UNIX_TIMESTAMP(NOW()) WHERE id > ? AND name LIKE ? AND (id_card IS NULL OR status IN (?, ?, ?)) AND modified_at > created_at + ? ORDER BY id ASC IF type = ? AND ready = ?
58-
// [sys 1234 %Du 1 2 5 86400 sys true]
53+
// UPDATE demo.user SET type = ?, credit = credit + 1, modified_at = UNIX_TIMESTAMP(NOW()) WHERE id > ? AND name LIKE ? AND (id_card IS NULL OR status IN (?, ?, ?)) AND modified_at > created_at + ? ORDER BY id ASC
54+
// [sys 1234 %Du 1 2 5 86400]
5955
}
6056

6157
func TestUpdateAssignments(t *testing.T) {

0 commit comments

Comments
 (0)