MCPcopy
hub / github.com/ory/keto / buildInsertUUIDs

Function buildInsertUUIDs

internal/persistence/sql/uuid_mapping.go:152–186  ·  view source on GitHub ↗
(values []UUIDMapping, dialect string)

Source from the content-addressed store, hash-verified

150}
151
152func buildInsertUUIDs(values []UUIDMapping, dialect string) (query string, args []any) {
153 if len(values) == 0 {
154 return "", nil
155 }
156
157 const placeholder = "(?,?)"
158 const separator = ","
159
160 var q strings.Builder
161 args = make([]any, 0, len(values)*2)
162
163 if dialect == "mysql" {
164 q.WriteString("INSERT IGNORE INTO keto_uuid_mappings (id, string_representation) VALUES ")
165 } else {
166 q.WriteString("INSERT INTO keto_uuid_mappings (id, string_representation) VALUES ")
167 }
168
169 q.Grow(len(values)*(len(placeholder)+len(separator)) + 100)
170
171 for i, val := range values {
172 if i > 0 {
173 q.WriteString(separator)
174 }
175 q.WriteString(placeholder)
176 args = append(args, val.ID, val.StringRepresentation)
177 }
178
179 if dialect == "mysql" {
180 // nothing
181 } else {
182 q.WriteString(" ON CONFLICT (id) DO NOTHING")
183 }
184
185 return q.String(), args
186}

Callers 2

MapStringsToUUIDsMethod · 0.85
TestBuildInsertUUIDsFunction · 0.85

Calls 1

StringMethod · 0.65

Tested by 1

TestBuildInsertUUIDsFunction · 0.68