/
02_implementation.go
58 lines (44 loc) · 1.13 KB
/
02_implementation.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
package data
import (
"context"
"database/sql"
)
type DatabaseImpl struct {
db *sql.DB
}
func (c *DatabaseImpl) QueryRowContext(ctx context.Context, query string, args ...interface{}) Row {
return c.db.QueryRowContext(ctx, query, args...)
}
func (c *DatabaseImpl) QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error) {
return c.db.QueryContext(ctx, query, args...)
}
func (c *DatabaseImpl) ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error) {
return c.db.ExecContext(ctx, query, args...)
}
type RowImpl struct {
row *sql.Row
}
func (r *RowImpl) Scan(dest ...interface{}) error {
return r.row.Scan(dest...)
}
type RowsImpl struct {
rows *sql.Rows
}
func (r RowsImpl) Scan(dest ...interface{}) error {
return r.rows.Scan(dest...)
}
func (r RowsImpl) Close() error {
return r.rows.Close()
}
func (r RowsImpl) Next() bool {
return r.rows.Next()
}
type ResultImpl struct {
result sql.Result
}
func (r *ResultImpl) LastInsertId() (int64, error) {
return r.result.LastInsertId()
}
func (r *ResultImpl) RowsAffected() (int64, error) {
return r.result.RowsAffected()
}