| 150 | } |
| 151 | |
| 152 | func 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 | } |