forked from pgpkg/pgpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtx.go
More file actions
43 lines (35 loc) · 802 Bytes
/
tx.go
File metadata and controls
43 lines (35 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package pgpkg
import (
"database/sql"
"strings"
)
type PkgTx struct {
*sql.Tx
}
func (t *PkgTx) Exec(query string, args ...any) (sql.Result, error) {
t.logQuery(query, args)
return t.Tx.Exec(query, args...)
}
func (t *PkgTx) Query(query string, args ...any) (*sql.Rows, error) {
t.logQuery(query, args)
return t.Tx.Query(query, args...)
}
func (t *PkgTx) QueryRow(query string, args ...any) *sql.Row {
t.logQuery(query, args)
return t.Tx.QueryRow(query, args...)
}
func (t *PkgTx) logQuery(query string, args []any) {
if !Options.Verbose {
return
}
logText := query
newLine := strings.IndexRune(logText, '\n')
if newLine >= 0 {
logText = logText[:newLine] + "…"
}
if args == nil || len(args) == 0 {
Verbose.Println(logText)
} else {
Verbose.Println(query, args)
}
}