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

axkit / velum / 22798729651

07 Mar 2026 12:03PM UTC coverage: 89.14%. First build
22798729651

Pull #2

regorov
fix readme
Pull Request #2: Feature/1 add arbitrary select

587 of 643 new or added lines in 10 files covered. (91.29%)

1576 of 1768 relevant lines covered (89.14%)

1.0 hits per line

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

21.31
/sqlw/sqlw.go
1
// Package sqlw adapts *sql.DB and *sql.Tx from the standard database/sql
2
// package to the velum.DatabaseWrapper and velum.Transaction interfaces.
3
// Use NewDatabaseWrapper to create a wrapper around an existing *sql.DB.
4
package sqlw
5

6
import (
7
        "context"
8
        "database/sql"
9
        "errors"
10

11
        "github.com/axkit/velum"
12
)
13

14
// DatabaseWrapper wraps *sql.DB to implement velum.DatabaseWrapper.
15
// Create it with NewDatabaseWrapper and pass it to Table and Dataset methods.
16
type DatabaseWrapper struct {
17
        db *sql.DB
18
}
19

20
// TransactionWrapper wraps *sql.Tx to implement velum.Transaction.
21
// It is returned by DatabaseWrapper.Begin and used inside DatabaseWrapper.InTx.
22
type TransactionWrapper struct {
23
        tx *sql.Tx
24
}
25

26
// RowsWrapper wraps *sql.Rows to implement velum.Rows. It overrides Close so
27
// that it always returns a non-nil error interface, matching the velum.Rows
28
// contract (sql.Rows.Close returns void before Go 1.22 in some contexts).
29
type RowsWrapper struct {
30
        sql.Rows
31
}
32

33
func (rw *RowsWrapper) Close() error {
×
34
        rw.Rows.Close()
×
35
        return nil
×
36
}
×
37

38
// ResultWrapper adapts a row-count value to velum.Result.
39
type ResultWrapper struct {
40
        rowsAffected int64
41
}
42

43
// RowsAffected returns the number of rows affected by the statement.
NEW
44
func (rw *ResultWrapper) RowsAffected() (int64, error) {
×
NEW
45
        return rw.rowsAffected, nil
×
46
}
×
47

48
// RowWrapper wraps *sql.Row to implement velum.Row. It adds the Err() method
49
// required by velum.Row (sql.Row exposes Err() starting in Go 1.15, but the
50
// velum.Row interface requires it unconditionally).
51
type RowWrapper struct {
52
        sql.Row
53
}
54

55
// Err always returns nil because sql.Row surfaces errors through Scan.
56
func (rw *RowWrapper) Err() error {
×
57
        return nil
×
58
}
×
59

60
// NewDatabaseWrapper wraps db and returns a DatabaseWrapper that implements
61
// velum.DatabaseWrapper using database/sql.
62
func NewDatabaseWrapper(db *sql.DB) *DatabaseWrapper {
1✔
63
        return &DatabaseWrapper{db: db}
1✔
64
}
1✔
65

66
// DB returns the underlying *sql.DB.
NEW
67
func (dw *DatabaseWrapper) DB() *sql.DB {
×
NEW
68
        return dw.db
×
69
}
×
70

71
// IsNotFound reports whether err represents a "no rows" condition
72
// (sql.ErrNoRows).
NEW
73
func (dw *DatabaseWrapper) IsNotFound(err error) bool {
×
74
        return errors.Is(err, sql.ErrNoRows)
×
75
}
×
76

77
// ExecContext executes a statement that does not return rows.
NEW
78
func (dw *DatabaseWrapper) ExecContext(ctx context.Context, query string, args ...any) (velum.Result, error) {
×
NEW
79
        return dw.db.ExecContext(ctx, query, args...)
×
80
}
×
81

82
// QueryRowContext executes a query that returns at most one row.
NEW
83
func (dw *DatabaseWrapper) QueryRowContext(ctx context.Context, sql string, args ...any) velum.Row {
×
NEW
84
        return dw.db.QueryRowContext(ctx, sql, args...)
×
85
}
×
86

87
// QueryContext executes a query that returns multiple rows.
NEW
88
func (dw *DatabaseWrapper) QueryContext(ctx context.Context, sql string, args ...any) (velum.Rows, error) {
×
NEW
89
        return dw.db.QueryContext(ctx, sql, args...)
×
90
}
×
91

92
// InTx executes fn inside a database/sql transaction. The transaction is
93
// committed if fn returns nil; otherwise it is rolled back.
94
func (dw *DatabaseWrapper) InTx(ctx context.Context, fn func(tx velum.Transaction) error) error {
1✔
95
        tx, err := dw.Begin(ctx)
1✔
96
        if err != nil {
2✔
97
                return err
1✔
98
        }
1✔
99
        defer func() {
×
100
                if err != nil {
×
101
                        tx.Rollback(ctx)
×
102
                } else {
×
103
                        err = tx.Commit(ctx)
×
104
                }
×
105
        }()
106

107
        return fn(&tx)
×
108
}
109

110
// Begin starts a new database/sql transaction and returns a TransactionWrapper.
111
func (dw *DatabaseWrapper) Begin(ctx context.Context) (TransactionWrapper, error) {
1✔
112
        tx, err := dw.db.BeginTx(ctx, nil)
1✔
113
        if err != nil {
2✔
114
                return TransactionWrapper{}, err
1✔
115
        }
1✔
116
        return TransactionWrapper{tx: tx}, nil
×
117
}
118

119
// Commit commits the transaction.
NEW
120
func (tw *TransactionWrapper) Commit(ctx context.Context) error {
×
NEW
121
        return tw.tx.Commit()
×
122
}
×
123

124
// Rollback aborts the transaction.
NEW
125
func (tw *TransactionWrapper) Rollback(ctx context.Context) error {
×
NEW
126
        return tw.tx.Rollback()
×
127
}
×
128

129
const doPrint = false
130

131
// ExecContext executes a statement inside the transaction that does not return rows.
132
func (tw *TransactionWrapper) ExecContext(ctx context.Context, sql string, args ...any) (velum.Result, error) {
×
133
        return tw.tx.ExecContext(ctx, sql, args...)
×
134
}
×
135

136
// QueryRowContext executes a query inside the transaction that returns at most one row.
137
func (tw *TransactionWrapper) QueryRowContext(ctx context.Context, sql string, args ...any) velum.Row {
×
138
        return tw.tx.QueryRowContext(ctx, sql, args...)
×
139
}
×
140

141
// QueryContext executes a query inside the transaction that returns multiple rows.
NEW
142
func (tw *TransactionWrapper) QueryContext(ctx context.Context, sql string, args ...any) (velum.Rows, error) {
×
NEW
143
        return tw.tx.QueryContext(ctx, sql, args...)
×
NEW
144
}
×
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