-
-
Notifications
You must be signed in to change notification settings - Fork 171
/
insert.go
45 lines (37 loc) · 987 Bytes
/
insert.go
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
//nolint:errcheck
package psql
import (
"github.com/dosco/graphjin/core/v3/internal/qcode"
"github.com/dosco/graphjin/core/v3/internal/sdata"
)
func (c *compilerContext) renderInsert() {
i := 0
for _, m := range c.qc.Mutates {
switch {
case m.Type == qcode.MTInsert:
i = c.renderComma(i)
c.renderInsertStmt(m, false)
case m.Type == qcode.MTUpsert:
i = c.renderComma(i)
c.renderInsertStmt(m, true)
case m.Rel.Type == sdata.RelOneToOne && m.Type == qcode.MTConnect:
i = c.renderComma(i)
c.renderOneToOneConnectStmt(m)
}
}
}
func (c *compilerContext) renderInsertStmt(m qcode.Mutate, embedded bool) {
c.renderCteName(m)
c.w.WriteString(` AS (`)
c.renderOneToManyModifiers(m)
c.w.WriteString(`INSERT INTO `)
c.table(m.Ti.Schema, m.Ti.Name, false)
c.w.WriteString(` (`)
n := c.renderInsertUpdateColumns(m)
c.renderNestedRelColumns(m, false, false, n)
c.w.WriteString(`)`)
c.renderValues(m, false)
if !embedded {
c.renderReturning(m)
}
}