-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert_builder.go
More file actions
55 lines (49 loc) · 1.37 KB
/
insert_builder.go
File metadata and controls
55 lines (49 loc) · 1.37 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package squildx
// InsertBuilder provides a fluent, immutable API for constructing INSERT queries.
type InsertBuilder interface {
Into(table string) InsertBuilder
Columns(columns ...string) InsertBuilder
ColumnsObject(obj any) InsertBuilder
Values(sql string, params ...Params) InsertBuilder
ValuesObject(obj any) InsertBuilder
Select(sub Builder) InsertBuilder
OnConflictDoNothing(columns ...string) InsertBuilder
OnConflictDoUpdate(columns []string, set string, params ...Params) InsertBuilder
Returning(columns ...string) InsertBuilder
ReturningObject(obj any) InsertBuilder
Build() (string, Params, error)
}
type insertBuilder struct {
table string
columns []string
valueRows []paramClause
selectQuery Builder
conflict *conflictClause
returnings []string
paramPrefix byte
err error
}
type conflictClause struct {
columns []string
doUpdate bool
set string
params Params
}
func NewInsert() InsertBuilder {
return &insertBuilder{}
}
func (b *insertBuilder) clone() *insertBuilder {
cp := *b
cp.columns = copySlice(b.columns)
cp.valueRows = copySlice(b.valueRows)
cp.returnings = copySlice(b.returnings)
if b.conflict != nil {
cc := *b.conflict
cc.columns = copySlice(b.conflict.columns)
cp.conflict = &cc
}
return &cp
}
func (b *insertBuilder) setPrefix(prefix byte) error {
return checkSetPrefix(&b.paramPrefix, prefix)
}