dialect/sql/sqlgraph: changing the M2M creation semantic from Add to Connect

Thus, calling AddE with the same edge values, ignore and not throw an error.
For edge-schemas with extra fields, we maintain the same logic because we cannot
determine if the extra fields have different values that what exist in the database
This commit is contained in:
Ariel Mashraki
2022-11-20 12:26:40 +02:00
committed by Ariel Mashraki
parent 4c9d61cf16
commit aa3d21f01a
39 changed files with 5234 additions and 55 deletions

View File

@@ -777,7 +777,7 @@ func ConflictWhere(p *Predicate) ConflictOption {
}
}
// UpdateWhere allows setting the an update condition. Only rows
// UpdateWhere allows setting the update condition. Only rows
// for which this expression returns true will be updated.
func UpdateWhere(p *Predicate) ConflictOption {
return func(c *conflict) {
@@ -985,8 +985,10 @@ func (i *InsertBuilder) writeConflict(b *Builder) {
switch i.Dialect() {
case dialect.MySQL:
b.WriteString(" ON DUPLICATE KEY UPDATE ")
// Fallback to ResolveWithIgnore() as MySQL
// does not support the "DO NOTHING" clause.
if i.conflict.action.nothing {
b.AddError(fmt.Errorf("invalid CONFLICT action ('DO NOTHING')"))
i.OnConflict(ResolveWithIgnore())
}
case dialect.SQLite, dialect.Postgres:
b.WriteString(" ON CONFLICT")