/
pop.go
77 lines (72 loc) · 2.23 KB
/
pop.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package hnypop
import (
"context"
"database/sql"
"math/rand"
"github.com/gobuffalo/pop/v6"
"github.com/honeycombio/beeline-go/wrappers/hnysqlx"
"github.com/jmoiron/sqlx"
)
type DB struct {
DB *hnysqlx.DB
tx *pop.Tx
}
func (m *DB) Select(dest interface{}, query string, args ...interface{}) error {
return m.DB.Select(dest, query, args...)
}
func (m *DB) Get(dest interface{}, query string, args ...interface{}) error {
return m.DB.Get(dest, query, args...)
}
func (m *DB) NamedExec(query string, arg interface{}) (sql.Result, error) {
return m.DB.NamedExec(query, arg)
}
func (m *DB) Exec(query string, args ...interface{}) (sql.Result, error) {
return m.DB.Exec(query, args...)
}
func (m *DB) PrepareNamed(query string) (*sqlx.NamedStmt, error) {
stmt, err := m.DB.PrepareNamed(query)
return stmt.GetWrappedNamedStmt(), err
}
func (m *DB) Transaction() (*pop.Tx, error) {
t := &pop.Tx{
ID: rand.Int(),
}
tx, err := m.DB.Beginx()
t.Tx = tx.GetWrappedTx()
m.tx = t
return t, err
}
func (m *DB) Rollback() error {
return m.tx.Rollback()
}
func (m *DB) Commit() error {
return m.tx.Commit()
}
func (m *DB) Close() error {
return m.Close()
}
func (m *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
return m.DB.SelectContext(ctx, dest, query, args...)
}
func (m *DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
return m.DB.GetContext(ctx, dest, query, args...)
}
func (m *DB) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error) {
return m.DB.NamedExecContext(ctx, query, arg)
}
func (m *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
return m.DB.ExecContext(ctx, query, args...)
}
func (m *DB) PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error) {
p, err := m.DB.PrepareNamedContext(ctx, query)
if err != nil {
return nil, err
}
return p.GetWrappedNamedStmt(), err
}
func (m *DB) TransactionContext(ctx context.Context) (*pop.Tx, error) {
return m.tx.TransactionContext(ctx)
}
func (m *DB) TransactionContextOptions(ctx context.Context, options *sql.TxOptions) (*pop.Tx, error) {
return m.tx.TransactionContextOptions(ctx, options)
}