MCPcopy Index your code
hub / github.com/cloudquery/cloudquery / getInsertQueryBuild

Function getInsertQueryBuild

plugins/destination/mysql/client/write.go:14–47  ·  view source on GitHub ↗
(table *schema.Table, rowCount int, overwrite bool)

Source from the content-addressed store, hash-verified

12)
13
14func getInsertQueryBuild(table *schema.Table, rowCount int, overwrite bool) *strings.Builder {
15 builder := strings.Builder{}
16 builder.WriteString("INSERT INTO " + identifier(table.Name))
17 builder.WriteString(" (")
18
19 for i, col := range table.Columns {
20 builder.WriteString(identifier(col.Name))
21 if i < len(table.Columns)-1 {
22 builder.WriteString(", ")
23 }
24 }
25 builder.WriteString(") VALUES ")
26
27 for i := 1; i <= rowCount; i++ {
28 if i > 1 {
29 builder.WriteString(", ")
30 }
31 builder.WriteString("(")
32 builder.WriteString(strings.TrimSuffix(strings.Repeat("?,", len(table.Columns)), ","))
33 builder.WriteString(")")
34 }
35
36 if overwrite {
37 builder.WriteString(" ON DUPLICATE KEY UPDATE ")
38 for i, col := range table.Columns {
39 builder.WriteString(fmt.Sprintf("%s = VALUES(%s)", identifier(col.Name), identifier(col.Name)))
40 if i < len(table.Columns)-1 {
41 builder.WriteString(", ")
42 }
43 }
44 }
45
46 return &builder
47}
48
49func logTablesWithTruncation(logger zerolog.Logger, tables map[string]bool) {
50 if len(tables) == 0 {

Callers 1

writeResourcesMethod · 0.85

Calls 1

identifierFunction · 0.70

Tested by

no test coverage detected