-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathinsert_stmt.go
More file actions
64 lines (54 loc) · 1.39 KB
/
insert_stmt.go
File metadata and controls
64 lines (54 loc) · 1.39 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
56
57
58
59
60
61
62
63
64
package ast
import "github.com/sqlc-dev/sqlc/internal/sql/format"
type InsertStmt struct {
Relation *RangeVar
Cols *List
SelectStmt Node
OnConflictClause *OnConflictClause
OnDuplicateKeyUpdate *OnDuplicateKeyUpdate // MySQL-specific
ReturningList *List
WithClause *WithClause
Override OverridingKind
DefaultValues bool // SQLite-specific: INSERT INTO ... DEFAULT VALUES
IsReplace bool // MySQL-specific
IgnoreErr bool // MySQL-specific
}
func (n *InsertStmt) Pos() int {
return 0
}
func (n *InsertStmt) Format(buf *TrackedBuffer, d format.Dialect) {
if n == nil {
return
}
if n.WithClause != nil {
buf.astFormat(n.WithClause, d)
buf.WriteString(" ")
}
buf.WriteString("INSERT INTO ")
if n.Relation != nil {
buf.astFormat(n.Relation, d)
}
if items(n.Cols) {
buf.WriteString(" (")
buf.astFormat(n.Cols, d)
buf.WriteString(")")
}
if n.DefaultValues {
buf.WriteString(" DEFAULT VALUES")
} else if set(n.SelectStmt) {
buf.WriteString(" ")
buf.astFormat(n.SelectStmt, d)
}
if n.OnConflictClause != nil {
buf.WriteString(" ")
buf.astFormat(n.OnConflictClause, d)
}
if n.OnDuplicateKeyUpdate != nil {
buf.WriteString(" ")
buf.astFormat(n.OnDuplicateKeyUpdate, d)
}
if items(n.ReturningList) {
buf.WriteString(" RETURNING ")
buf.astFormat(n.ReturningList, d)
}
}