Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ $ go mod edit -replace github.com/codahale/hdrhistogram=github.com/HdrHistogram/

* Add gRPC client tracing methods
* Fix github.com/codahale/hdrhistogram dependency import issue

#### v9.3.0

* Fix postgresql transaction orm operations.

24 changes: 24 additions & 0 deletions pg/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,65 @@ type DB struct {

// Select calls inner db select
func (db *DB) Select(model interface{}) error {
if db.tx != nil {
return db.tx.Select(model)
}
return db.inner.Select(model)
}

// Insert calls inner db insert
func (db *DB) Insert(model ...interface{}) error {
if db.tx != nil {
return db.tx.Insert(model...)
}
return db.inner.Insert(model...)
}

// Update calls inner db update
func (db *DB) Update(model interface{}) error {
if db.tx != nil {
return db.tx.Update(model)
}
return db.inner.Update(model)
}

// Delete calls inner db delete
func (db *DB) Delete(model interface{}) error {
if db.tx != nil {
return db.tx.Delete(model)
}
return db.inner.Delete(model)
}

// ForceDelete calls inner db force delete
func (db *DB) ForceDelete(model interface{}) error {
if db.tx != nil {
return db.tx.ForceDelete(model)
}
return db.inner.ForceDelete(model)
}

// CopyFrom calls inner db copyFrom
func (db *DB) CopyFrom(r io.Reader, query interface{}, params ...interface{}) (orm.Result, error) {
if db.tx != nil {
return db.tx.CopyFrom(r, query, params...)
}
return db.inner.CopyFrom(r, query, params...)
}

// CopyTo calls inner db copyTo
func (db *DB) CopyTo(w io.Writer, query interface{}, params ...interface{}) (orm.Result, error) {
if db.tx != nil {
return db.tx.CopyTo(w, query, params...)
}
return db.inner.CopyTo(w, query, params...)
}

// FormatQuery calls inner db formatQuery
func (db *DB) FormatQuery(b []byte, query string, params ...interface{}) []byte {
if db.tx != nil {
return db.tx.FormatQuery(b, query, params...)
}
return db.inner.FormatQuery(b, query, params...)
}

Expand Down
1 change: 1 addition & 0 deletions pg/interfaces/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type DB interface {
// Tx represents the contract for a Postgres Tx
type Tx interface {
Queryable
ORM
Rollback() error
Commit() error
}
Expand Down
Loading