Skip to content
Snippets Groups Projects
Commit 299043c82fc0 authored by Christophe de Vienne's avatar Christophe de Vienne
Browse files

SQLHelper: add SyncRelationStrings

parent fe82db40aa33
No related branches found
No related tags found
No related merge requests found
Pipeline #6599 passed
......@@ -71,3 +71,30 @@
}
return nil
}
// SyncRelationStrings ...
func (h *SQLHelper) SyncRelationStrings(
table string, colFrom string, colTo string,
colFromValue string, colToValues []string,
) error {
// Upsert ts les couples
q := sq.Insert(table).
Columns(colFrom, colTo)
for _, value := range colToValues {
q = q.Values(colFromValue, value)
}
q = q.Suffix("ON CONFLICT DO NOTHING")
if _, err := h.Exec(q); err != nil {
return err
}
filter := sq.And{sq.Eq{colFrom: colFromValue}}
for _, value := range colToValues {
filter = append(filter, sq.NotEq{colTo: value})
}
// Delete les valeurs non voulues
if _, err := h.Exec(sq.Delete(table).Where(filter)); err != nil {
return err
}
return nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment