• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

axkit / velum / 14344779540

08 Apr 2025 10:21PM UTC coverage: 60.174% (-1.5%) from 61.7%
14344779540

push

regorov
add generic not found error

1 of 34 new or added lines in 4 files covered. (2.94%)

763 of 1268 relevant lines covered (60.17%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/sqlw/sqlw.go
1
package sqlw
2

3
import (
4
        "context"
5
        "database/sql"
6
        "errors"
7
        "fmt"
8

9
        "github.com/axkit/velum"
10
)
11

12
type DatabaseWrapper struct {
13
        db *sql.DB
14
}
15

16
type TransactionWrapper struct {
17
        tx *sql.Tx
18
}
19

20
type RowsWrapper struct {
21
        sql.Rows
22
}
23

24
func (rw *RowsWrapper) Close() error {
×
25
        rw.Rows.Close()
×
26
        return nil
×
27
}
×
28

29
type ResultWrapper struct {
30
        rowsAffected int64
31
}
32

33
func (r *ResultWrapper) RowsAffected() (int64, error) {
×
34
        return r.rowsAffected, nil
×
35
}
×
36

37
type RowWrapper struct {
38
        sql.Row
39
}
40

41
func (rw *RowWrapper) Err() error {
×
42
        return nil
×
43
}
×
44

45
func NewDatabaseWrapper(db *sql.DB) *DatabaseWrapper {
×
46
        return &DatabaseWrapper{db: db}
×
47
}
×
48

49
func (w *DatabaseWrapper) DB() *sql.DB {
×
50
        return w.db
×
51
}
×
52

NEW
53
func (w *DatabaseWrapper) IsNotFound(err error) bool {
×
NEW
54
        return errors.Is(err, sql.ErrNoRows)
×
NEW
55
}
×
56

57
func (w *DatabaseWrapper) ExecContext(ctx context.Context, query string, args ...any) (velum.Result, error) {
×
58
        return w.db.ExecContext(ctx, query, args...)
×
59
}
×
60

61
func (w *DatabaseWrapper) QueryContext(ctx context.Context, sql string, args ...any) (velum.Rows, error) {
×
62
        return w.db.QueryContext(ctx, sql, args...)
×
63
}
×
64

65
func (w *DatabaseWrapper) QueryRowContext(ctx context.Context, sql string, args ...any) velum.Row {
×
66
        return w.db.QueryRowContext(ctx, sql, args...)
×
67
}
×
68

69
func (w *DatabaseWrapper) InTx(ctx context.Context, fn func(tx velum.Transaction) error) error {
×
70
        tx, err := w.Begin(ctx)
×
71
        if err != nil {
×
72
                return err
×
73
        }
×
74
        defer func() {
×
75
                if err != nil {
×
76
                        tx.Rollback(ctx)
×
77
                } else {
×
78
                        err = tx.Commit(ctx)
×
79
                }
×
80
        }()
81

82
        return fn(&tx)
×
83
}
84

85
func (w *DatabaseWrapper) Begin(ctx context.Context) (TransactionWrapper, error) {
×
86
        tx, err := w.db.Begin()
×
87
        if err != nil {
×
88
                return TransactionWrapper{}, err
×
89
        }
×
90
        return TransactionWrapper{tx: tx}, nil
×
91
}
92

93
func (tx *TransactionWrapper) Commit(ctx context.Context) error {
×
94
        return tx.tx.Commit()
×
95
}
×
96

97
func (tx *TransactionWrapper) Rollback(ctx context.Context) error {
×
98
        return tx.tx.Rollback()
×
99
}
×
100

101
const doPrint = false
102

103
func (tw *TransactionWrapper) ExecContext(ctx context.Context, sql string, args ...any) (velum.Result, error) {
×
104
        if doPrint {
×
105
                fmt.Printf("TransactionWrapper.ExecContext: %d: %s\n", len(args), sql)
×
106
        }
×
107
        return tw.tx.ExecContext(ctx, sql, args...)
×
108
}
109

110
func (tw *TransactionWrapper) QueryContext(ctx context.Context, sql string, args ...any) (velum.Rows, error) {
×
111
        if doPrint {
×
112
                fmt.Printf("TransactionWrapper.QueryContext: %d: %s\n", len(args), sql)
×
113
        }
×
114
        return tw.tx.QueryContext(ctx, sql, args...)
×
115
        //return &RowsWrapper{res}, err
116
}
117

118
func (tw *TransactionWrapper) QueryRowContext(ctx context.Context, sql string, args ...any) velum.Row {
×
119
        if doPrint {
×
120
                fmt.Printf("TransactionWrapper.QueryRowContext: %d: %s\n", len(args), sql)
×
121
        }
×
122
        return tw.tx.QueryRowContext(ctx, sql, args...)
×
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc