Add For query mod

This commit is contained in:
Patrick O'brien 2016-08-30 13:13:00 +10:00
parent bc602811a8
commit d735c3df36
3 changed files with 17 additions and 0 deletions

View file

@ -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)
}
}

View file

@ -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

View file

@ -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 {