/
db.go
278 lines (221 loc) · 9.63 KB
/
db.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package mock
import (
"context"
"github.com/go-kivik/kivik/v3/driver"
)
// DB mocks a driver.DB
type DB struct {
// ID is a unique identifier for the DB instance.
ID string
AllDocsFunc func(ctx context.Context, options map[string]interface{}) (driver.Rows, error)
GetFunc func(ctx context.Context, docID string, options map[string]interface{}) (*driver.Document, error)
CreateDocFunc func(ctx context.Context, doc interface{}, options map[string]interface{}) (docID, rev string, err error)
PutFunc func(ctx context.Context, docID string, doc interface{}, options map[string]interface{}) (rev string, err error)
DeleteFunc func(ctx context.Context, docID, rev string, options map[string]interface{}) (newRev string, err error)
StatsFunc func(ctx context.Context) (*driver.DBStats, error)
CompactFunc func(ctx context.Context) error
CompactViewFunc func(ctx context.Context, ddocID string) error
ViewCleanupFunc func(ctx context.Context) error
SecurityFunc func(ctx context.Context) (*driver.Security, error)
SetSecurityFunc func(ctx context.Context, security *driver.Security) error
ChangesFunc func(ctx context.Context, options map[string]interface{}) (driver.Changes, error)
PutAttachmentFunc func(ctx context.Context, docID, rev string, att *driver.Attachment, options map[string]interface{}) (newRev string, err error)
GetAttachmentFunc func(ctx context.Context, docID, filename string, options map[string]interface{}) (*driver.Attachment, error)
DeleteAttachmentFunc func(ctx context.Context, docID, rev, filename string, options map[string]interface{}) (newRev string, err error)
QueryFunc func(context.Context, string, string, map[string]interface{}) (driver.Rows, error)
}
var _ driver.DB = &DB{}
// AllDocs calls db.AllDocsFunc
func (db *DB) AllDocs(ctx context.Context, options map[string]interface{}) (driver.Rows, error) {
return db.AllDocsFunc(ctx, options)
}
// Get calls db.GetFunc
func (db *DB) Get(ctx context.Context, docID string, opts map[string]interface{}) (*driver.Document, error) {
return db.GetFunc(ctx, docID, opts)
}
// CreateDoc calls db.CreateDocFunc
func (db *DB) CreateDoc(ctx context.Context, doc interface{}, opts map[string]interface{}) (string, string, error) {
return db.CreateDocFunc(ctx, doc, opts)
}
// Put calls db.PutFunc
func (db *DB) Put(ctx context.Context, docID string, doc interface{}, opts map[string]interface{}) (string, error) {
return db.PutFunc(ctx, docID, doc, opts)
}
// Delete calls db.DeleteFunc
func (db *DB) Delete(ctx context.Context, docID, rev string, opts map[string]interface{}) (string, error) {
return db.DeleteFunc(ctx, docID, rev, opts)
}
// Stats calls db.StatsFunc
func (db *DB) Stats(ctx context.Context) (*driver.DBStats, error) {
return db.StatsFunc(ctx)
}
// Compact calls db.CompactFunc
func (db *DB) Compact(ctx context.Context) error {
return db.CompactFunc(ctx)
}
// CompactView calls db.CompactViewFunc
func (db *DB) CompactView(ctx context.Context, docID string) error {
return db.CompactViewFunc(ctx, docID)
}
// ViewCleanup calls db.ViewCleanupFunc
func (db *DB) ViewCleanup(ctx context.Context) error {
return db.ViewCleanupFunc(ctx)
}
// Security calls db.SecurityFunc
func (db *DB) Security(ctx context.Context) (*driver.Security, error) {
return db.SecurityFunc(ctx)
}
// SetSecurity calls db.SetSecurityFunc
func (db *DB) SetSecurity(ctx context.Context, security *driver.Security) error {
return db.SetSecurityFunc(ctx, security)
}
// Changes calls db.ChangesFunc
func (db *DB) Changes(ctx context.Context, opts map[string]interface{}) (driver.Changes, error) {
return db.ChangesFunc(ctx, opts)
}
// PutAttachment calls db.PutAttachmentFunc
func (db *DB) PutAttachment(ctx context.Context, docID, rev string, att *driver.Attachment, opts map[string]interface{}) (string, error) {
return db.PutAttachmentFunc(ctx, docID, rev, att, opts)
}
// GetAttachment calls db.GetAttachmentFunc
func (db *DB) GetAttachment(ctx context.Context, docID, filename string, opts map[string]interface{}) (*driver.Attachment, error) {
return db.GetAttachmentFunc(ctx, docID, filename, opts)
}
// DeleteAttachment calls db.DeleteAttachmentFunc
func (db *DB) DeleteAttachment(ctx context.Context, docID, rev, filename string, opts map[string]interface{}) (string, error) {
return db.DeleteAttachmentFunc(ctx, docID, rev, filename, opts)
}
// Query calls db.QueryFunc
func (db *DB) Query(ctx context.Context, ddoc, view string, opts map[string]interface{}) (driver.Rows, error) {
return db.QueryFunc(ctx, ddoc, view, opts)
}
// Finder mocks a driver.DB and driver.Finder
type Finder struct {
*DB
CreateIndexFunc func(context.Context, string, string, interface{}) error
DeleteIndexFunc func(context.Context, string, string) error
FindFunc func(context.Context, interface{}) (driver.Rows, error)
GetIndexesFunc func(context.Context) ([]driver.Index, error)
ExplainFunc func(context.Context, interface{}) (*driver.QueryPlan, error)
}
var _ driver.Finder = &Finder{}
// CreateIndex calls db.CreateIndexFunc
func (db *Finder) CreateIndex(ctx context.Context, ddoc, name string, index interface{}) error {
return db.CreateIndexFunc(ctx, ddoc, name, index)
}
// DeleteIndex calls db.DeleteIndexFunc
func (db *Finder) DeleteIndex(ctx context.Context, ddoc, name string) error {
return db.DeleteIndexFunc(ctx, ddoc, name)
}
// Find calls db.FindFunc
func (db *Finder) Find(ctx context.Context, query interface{}) (driver.Rows, error) {
return db.FindFunc(ctx, query)
}
// GetIndexes calls db.GetIndexesFunc
func (db *Finder) GetIndexes(ctx context.Context) ([]driver.Index, error) {
return db.GetIndexesFunc(ctx)
}
// Explain calls db.ExplainFunc
func (db *Finder) Explain(ctx context.Context, query interface{}) (*driver.QueryPlan, error) {
return db.ExplainFunc(ctx, query)
}
// Flusher mocks a driver.DB and driver.Flusher
type Flusher struct {
*DB
FlushFunc func(context.Context) error
}
var _ driver.Flusher = &Flusher{}
// Flush calls db.FlushFunc
func (db *Flusher) Flush(ctx context.Context) error {
return db.FlushFunc(ctx)
}
// MetaGetter mocks a driver.DB and driver.MetaGetter
type MetaGetter struct {
*DB
GetMetaFunc func(context.Context, string, map[string]interface{}) (int64, string, error)
}
var _ driver.MetaGetter = &MetaGetter{}
// GetMeta calls db.GetMetaFunc
func (db *MetaGetter) GetMeta(ctx context.Context, docID string, opts map[string]interface{}) (int64, string, error) {
return db.GetMetaFunc(ctx, docID, opts)
}
// Copier mocks a driver.DB and driver.Copier.
type Copier struct {
*DB
CopyFunc func(context.Context, string, string, map[string]interface{}) (string, error)
}
var _ driver.Copier = &Copier{}
// Copy calls db.CopyFunc
func (db *Copier) Copy(ctx context.Context, target, source string, options map[string]interface{}) (string, error) {
return db.CopyFunc(ctx, target, source, options)
}
// AttachmentMetaGetter mocks a driver.DB and driver.AttachmentMetaGetter
type AttachmentMetaGetter struct {
*DB
GetAttachmentMetaFunc func(ctx context.Context, docID, filename string, options map[string]interface{}) (*driver.Attachment, error)
}
var _ driver.AttachmentMetaGetter = &AttachmentMetaGetter{}
// GetAttachmentMeta calls db.GetAttachmentMetaFunc
func (db *AttachmentMetaGetter) GetAttachmentMeta(ctx context.Context, docID, filename string, options map[string]interface{}) (*driver.Attachment, error) {
return db.GetAttachmentMetaFunc(ctx, docID, filename, options)
}
// DesignDocer mocks a driver.DB and driver.DesignDocer
type DesignDocer struct {
*DB
DesignDocsFunc func(context.Context, map[string]interface{}) (driver.Rows, error)
}
var _ driver.DesignDocer = &DesignDocer{}
// DesignDocs calls db.DesignDocsFunc
func (db *DesignDocer) DesignDocs(ctx context.Context, options map[string]interface{}) (driver.Rows, error) {
return db.DesignDocsFunc(ctx, options)
}
// LocalDocer mocks a driver.DB and driver.DesignDocer
type LocalDocer struct {
*DB
LocalDocsFunc func(context.Context, map[string]interface{}) (driver.Rows, error)
}
var _ driver.LocalDocer = &LocalDocer{}
// LocalDocs calls db.LocalDocsFunc
func (db *LocalDocer) LocalDocs(ctx context.Context, options map[string]interface{}) (driver.Rows, error) {
return db.LocalDocsFunc(ctx, options)
}
// Purger mocks a driver.DB and driver.Purger
type Purger struct {
*DB
PurgeFunc func(context.Context, map[string][]string) (*driver.PurgeResult, error)
}
var _ driver.Purger = &Purger{}
// Purge calls db.PurgeFunc
func (db *Purger) Purge(ctx context.Context, docMap map[string][]string) (*driver.PurgeResult, error) {
return db.PurgeFunc(ctx, docMap)
}
// BulkGetter mocks a driver.DB and driver.BulkGetter
type BulkGetter struct {
*DB
BulkGetFunc func(context.Context, []driver.BulkGetReference, map[string]interface{}) (driver.Rows, error)
}
var _ driver.BulkGetter = &BulkGetter{}
// BulkGet calls db.BulkGetFunc
func (db *BulkGetter) BulkGet(ctx context.Context, docs []driver.BulkGetReference, opts map[string]interface{}) (driver.Rows, error) {
return db.BulkGetFunc(ctx, docs, opts)
}
// DBCloser mocks driver.DB and driver.DBCloser
type DBCloser struct {
*DB
CloseFunc func(context.Context) error
}
var _ driver.DBCloser = &DBCloser{}
// Close calls db.CloseFunc
func (db *DBCloser) Close(ctx context.Context) error {
return db.CloseFunc(ctx)
}
// RevsDiffer mocks a driver.DB and driver.RevsDiffer.
type RevsDiffer struct {
*BulkDocer
RevsDiffFunc func(context.Context, interface{}) (driver.Rows, error)
}
var _ driver.RevsDiffer = &RevsDiffer{}
// RevsDiff calls db.RevsDiffFunc
func (db *RevsDiffer) RevsDiff(ctx context.Context, revMap interface{}) (driver.Rows, error) {
return db.RevsDiffFunc(ctx, revMap)
}