diff --git a/boil/qm/query_mods.go b/boil/qm/query_mods.go index f48d69e..3a06cd7 100644 --- a/boil/qm/query_mods.go +++ b/boil/qm/query_mods.go @@ -136,3 +136,10 @@ func Offset(offset int) QueryMod { boil.SetOffset(q, offset) } } + +// For inserts a concurrency locking clause at the end of your statement +func For(clause string) QueryMod { + return func(q *boil.Query) { + boil.SetFor(q, clause) + } +} diff --git a/boil/query.go b/boil/query.go index da97245..2ea37e9 100644 --- a/boil/query.go +++ b/boil/query.go @@ -34,6 +34,7 @@ type Query struct { having []having limit int offset int + forlock string } type where struct { @@ -150,6 +151,11 @@ func SetOffset(q *Query, offset int) { q.offset = offset } +// SetFor on the query. +func SetFor(q *Query, clause string) { + q.forlock = clause +} + // SetUpdate on the query. func SetUpdate(q *Query, cols map[string]interface{}) { q.update = cols diff --git a/boil/query_builders.go b/boil/query_builders.go index 634e9bd..097b1a2 100644 --- a/boil/query_builders.go +++ b/boil/query_builders.go @@ -205,6 +205,10 @@ func writeModifiers(q *Query, buf *bytes.Buffer, args *[]interface{}) { if q.offset != 0 { fmt.Fprintf(buf, " OFFSET %d", q.offset) } + + if len(q.forlock) != 0 { + fmt.Fprintf(buf, " FOR %s", q.forlock) + } } func writeStars(q *Query) []string {