From ea03b5a1ec35c76a8b378d83d03198a24c15d1c2 Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Tue, 17 Jul 2018 12:05:16 +0200 Subject: [PATCH] upd(vendor): update database profiler --- Gopkg.lock | 2 +- .../github.com/titpetric/factory/database.go | 39 ++++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 4ddd02f8c..8430a9deb 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -93,7 +93,7 @@ ".", "resputil" ] - revision = "b45ac8b1bb2f1a2fccd1530abb5f44f5f0de67f8" + revision = "48ba0357b31ad368f66fa2441bd23c12757c56a0" [[projects]] branch = "master" diff --git a/vendor/github.com/titpetric/factory/database.go b/vendor/github.com/titpetric/factory/database.go index 10b34483d..d4869a76d 100644 --- a/vendor/github.com/titpetric/factory/database.go +++ b/vendor/github.com/titpetric/factory/database.go @@ -218,22 +218,43 @@ func (r *DB) set(data interface{}) string { } // Replace is a helper function which will issue an `replace` statement to the database -func (r *DB) Replace(table string, data interface{}) error { - sql := "replace into " + table + " set " + r.set(data) - _, err := r.NamedExec(sql, data) +func (r *DB) Replace(table string, args interface{}) error { + var err error + query := "replace into " + table + " set " + r.set(args) + if r.Profiler != nil { + ctx := DatabaseProfilerContext{}.new(query, args) + _, err = r.NamedExec(query, args) + r.Profiler.Post(ctx) + } else { + _, err = r.NamedExec(query, args) + } return err } // Insert is a helper function which will issue an `insert` statement to the database -func (r *DB) Insert(table string, data interface{}) error { - sql := "insert into " + table + " set " + r.set(data) - _, err := r.NamedExec(sql, data) +func (r *DB) Insert(table string, args interface{}) error { + var err error + query := "insert into " + table + " set " + r.set(args) + if r.Profiler != nil { + ctx := DatabaseProfilerContext{}.new(query, args) + _, err = r.NamedExec(query, args) + r.Profiler.Post(ctx) + } else { + _, err = r.NamedExec(query, args) + } return err } // InsertIgnore is a helper function which will issue an `insert ignore` statement to the database -func (r *DB) InsertIgnore(table string, data interface{}) error { - sql := "insert ignore into " + table + " set " + r.set(data) - _, err := r.NamedExec(sql, data) +func (r *DB) InsertIgnore(table string, args interface{}) error { + var err error + query := "insert ignore into " + table + " set " + r.set(args) + if r.Profiler != nil { + ctx := DatabaseProfilerContext{}.new(query, args) + _, err = r.NamedExec(query, args) + r.Profiler.Post(ctx) + } else { + _, err = r.NamedExec(query, args) + } return err }