Skip to content

Commit

Permalink
#9: Add lockForUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Kushmantsev committed Aug 27, 2019
1 parent 8017b8d commit 6ce378f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
32 changes: 20 additions & 12 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ import (

// inner type to build qualified sql
type builder struct {
where string
whereNamed map[string]interface{}
table string
from string
join []string
orderBy map[string]string
groupBy string
having string
columns []string
union []string
offset int64
limit int64
where string
whereNamed map[string]interface{}
table string
from string
join []string
orderBy map[string]string
groupBy string
having string
columns []string
union []string
offset int64
limit int64
lockForUpdate *string
}

// DB is an entity that composite builder and Conn types
Expand Down Expand Up @@ -353,6 +354,13 @@ func (r *DB) From(fromTbl string) *DB {
return r
}

func (r *DB) LockForUpdate() *DB {
str := " FOR UPDATE"
r.Builder.lockForUpdate = &str

return r
}

// Dump prints raw sql to stdout
func (r *DB) Dump() {
log.SetOutput(os.Stdout)
Expand Down
4 changes: 4 additions & 0 deletions pgsql_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func (r *builder) buildSelect() string {
query += " OFFSET " + strconv.FormatInt(r.offset, 10)
}

if r.lockForUpdate != nil {
query += *r.lockForUpdate
}

return query
}

Expand Down

0 comments on commit 6ce378f

Please sign in to comment.