Skip to content

Commit

Permalink
fix: mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Sep 10, 2024
1 parent 01f199d commit 05027a7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions persistence/sql/batch/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ func Create[T any](ctx context.Context, p *TracerConnection, models []*T) (err e
if err != nil {
return sqlcon.HandleError(err)
}
// MySQL, which does not support RETURNING, also does not have ON CONFLICT DO
// NOTHING, meaning that MySQL will always fail the whole transaction on a single
// record conflict.
if conn.Dialect.Name() != dbal.DriverMySQL {
return sqlcon.HandleError(rows.Close())
}

idIdx := slices.Index(queryArgs.Columns, "id")
if idIdx == -1 {
Expand All @@ -196,9 +202,7 @@ func Create[T any](ctx context.Context, p *TracerConnection, models []*T) (err e
idValues = append(idValues, values[i].(uuid.UUID))
}

// Hydrate the models from the RETURNING clause. Note that MySQL, which does not
// support RETURNING, also does not have ON CONFLICT DO NOTHING, meaning that
// MySQL will always fail the whole transaction on a single record conflict.
// Hydrate the models from the RETURNING clause.
idsInDB := make(map[uuid.UUID]struct{})
for rows.Next() {
if err := rows.Err(); err != nil {
Expand Down

0 comments on commit 05027a7

Please sign in to comment.