Building dynamic ON_CONFLICT DO_UPDATE #276
-
I have several fields that might be updated, so instead of checking one by one, I tried to do something like: stmt := table.INSERT(columnList). and try to build columnList, model and conflictSql dynamically columnList is of type ColumnList, so I can append table.Col2 SET(table.col2.SET(value)) and SET is a func, so I can't declare var conflictSql []func{} and then append to it with SET(table.Col2.SET(value)) I tried to use an interface instead like var conflictSql []interface{}, and of course I can append, but then I'm not sure how to convert it to what DO_UPDATE expects (seems to be an internal type conflictAction) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I'm not sure what you mean. This should work: var columnAssigments []ColumnAssigment
columnAssigments = append(columnAssigments, table.col2.SET(value))
// ...
stmt := table.INSERT(columnList).
MODEL(model).
ON_CONFLICT(table.Col1).DO_UPDATE(
SET(
columnAssigments...,
)
) |
Beta Was this translation helpful? Give feedback.
I'm not sure what you mean. This should work: