txw.go 735 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package sqlw
  2. import (
  3. "database/sql"
  4. _ "github.com/go-sql-driver/mysql"
  5. "time"
  6. )
  7. type Tx struct {
  8. tx *sql.Tx
  9. s time.Time
  10. }
  11. func (this *Tx) Rollback() error {
  12. err := this.tx.Rollback()
  13. log("[TX] TRANSACTION END (Rollback)", this.s, true)
  14. return err
  15. }
  16. func (this *Tx) Commit() error {
  17. err := this.tx.Commit()
  18. log("[TX] TRANSACTION END (Commit)", this.s, true)
  19. return err
  20. }
  21. func (this *Tx) Exec(query string, args ...interface{}) (sql.Result, error) {
  22. s := time.Now()
  23. r, e := this.tx.Exec(query, args...)
  24. log("[TX] "+query, s, true)
  25. return r, e
  26. }
  27. func (this *Tx) QueryRow(query string, args ...interface{}) *sql.Row {
  28. s := time.Now()
  29. r := this.tx.QueryRow(query, args...)
  30. log("[TX] "+query, s, true)
  31. return r
  32. }