Skip to content

Commit

Permalink
Merge pull request #50 from ShiftLeftSecurity/olof/fix/more-variants
Browse files Browse the repository at this point in the history
Add variant to set SQL on updates without parens.
  • Loading branch information
Ferada authored Jun 1, 2021
2 parents 134c0ee + ec9e617 commit e63d7d8
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion db/chain/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (o *OnUpdate) Set(args ...interface{}) *OnUpdate {
}

// SetSQL Sets a field to a value that needs no escaping, it is assumed to be SQL valid (an
// expression or column)
// expression or column) and inserts parentheses around both keys and values
func (o *OnUpdate) SetSQL(args ...string) *OnUpdate {
if len(args)%2 != 0 {
panic("arguments to `DoUpdate().SetSQL(...)` must be even in length")
Expand All @@ -127,6 +127,25 @@ func (o *OnUpdate) SetSQL(args ...string) *OnUpdate {
return o
}

// SetSQLNoParens Sets a field to a value that needs no escaping, it is assumed to be SQL valid (an
// expression or column) and doesn't insert any parentheses around either keys or values
func (o *OnUpdate) SetSQLNoParens(args ...string) *OnUpdate {
if len(args)%2 != 0 {
panic("arguments to `DoUpdate().SetSQLNoParens(...)` must be even in length")
}
var key string
for index, arg := range args {
if index%2 == 0 {
key = arg
} else {
*o.operatorList = append(*o.operatorList, argList{
text: key + " = " + arg,
})
}
}
return o
}

// SetSQLRow Sets a field to a value that needs no escaping, it is assumed to be SQL valid (an
// expression or column) it will append ROW to the values part because pg 12 updates
func (o *OnUpdate) SetSQLRow(args ...string) *OnUpdate {
Expand Down

0 comments on commit e63d7d8

Please sign in to comment.