-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_builder.go
More file actions
41 lines (36 loc) · 1.09 KB
/
update_builder.go
File metadata and controls
41 lines (36 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package squildx
// UpdateBuilder provides a fluent, immutable API for constructing UPDATE queries.
type UpdateBuilder interface {
Table(table string) UpdateBuilder
Set(sql string, params ...Params) UpdateBuilder
SetObject(obj any) UpdateBuilder
Where(sql string, params ...Params) UpdateBuilder
WhereExists(sub Builder) UpdateBuilder
WhereNotExists(sub Builder) UpdateBuilder
WhereIn(column string, sub Builder) UpdateBuilder
WhereNotIn(column string, sub Builder) UpdateBuilder
Returning(columns ...string) UpdateBuilder
ReturningObject(obj any) UpdateBuilder
Build() (string, Params, error)
}
type updateBuilder struct {
table string
sets []paramClause
wheres []paramClause
returnings []string
paramPrefix byte
err error
}
func NewUpdate() UpdateBuilder {
return &updateBuilder{}
}
func (b *updateBuilder) clone() *updateBuilder {
cp := *b
cp.sets = copySlice(b.sets)
cp.wheres = copySlice(b.wheres)
cp.returnings = copySlice(b.returnings)
return &cp
}
func (b *updateBuilder) setPrefix(prefix byte) error {
return checkSetPrefix(&b.paramPrefix, prefix)
}