-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnop_adapter.go
100 lines (74 loc) · 2.09 KB
/
nop_adapter.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package reltest
import (
"context"
"github.com/go-rel/rel"
)
type nopAdapter struct{}
func (na *nopAdapter) Name() string {
return "nop"
}
func (na *nopAdapter) Close() error {
return nil
}
func (na *nopAdapter) Instrumentation(instrumenter rel.Instrumenter) {
}
func (na *nopAdapter) Ping(ctx context.Context) error {
return nil
}
func (na *nopAdapter) Aggregate(ctx context.Context, query rel.Query, mode string, field string) (int, error) {
return 0, nil
}
func (na *nopAdapter) Begin(ctx context.Context) (rel.Adapter, error) {
return na, nil
}
func (na *nopAdapter) Commit(ctx context.Context) error {
return nil
}
func (na *nopAdapter) Delete(ctx context.Context, query rel.Query) (int, error) {
return 1, nil
}
func (na *nopAdapter) Insert(ctx context.Context, query rel.Query, primaryField string, mutates map[string]rel.Mutate, onConflict rel.OnConflict) (any, error) {
return 1, nil
}
func (na *nopAdapter) InsertAll(ctx context.Context, query rel.Query, primaryField string, fields []string, bulkMutates []map[string]rel.Mutate, onConflict rel.OnConflict) ([]any, error) {
ids := make([]any, len(bulkMutates))
for i := range bulkMutates {
ids[i] = i + 1
}
return ids, nil
}
func (na *nopAdapter) Query(ctx context.Context, query rel.Query) (rel.Cursor, error) {
return &nopCursor{count: 1}, nil
}
func (na *nopAdapter) Rollback(ctx context.Context) error {
return nil
}
func (na *nopAdapter) Update(ctx context.Context, query rel.Query, primaryField string, mutates map[string]rel.Mutate) (int, error) {
return 1, nil
}
func (na *nopAdapter) Apply(ctx context.Context, migration rel.Migration) error {
return nil
}
func (na *nopAdapter) Exec(ctx context.Context, stmt string, args []any) (int64, int64, error) {
return 0, 0, nil
}
type nopCursor struct {
count int
}
func (nc *nopCursor) Close() error {
return nil
}
func (nc *nopCursor) Fields() ([]string, error) {
return nil, nil
}
func (nc *nopCursor) Next() bool {
nc.count--
return nc.count >= 0
}
func (nc *nopCursor) Scan(...any) error {
nc.NopScanner()
return nil
}
func (nc *nopCursor) NopScanner() any {
return nil
}