1
2
3
4
5
6
7
8
9
10
11
12
13 package mock
14
15 import (
16 "context"
17
18 "github.com/go-kivik/kivik/v4/driver"
19 )
20
21
22 type DB struct {
23
24 ID string
25 AllDocsFunc func(ctx context.Context, options driver.Options) (driver.Rows, error)
26 GetFunc func(ctx context.Context, docID string, options driver.Options) (*driver.Document, error)
27 PutFunc func(ctx context.Context, docID string, doc interface{}, options driver.Options) (rev string, err error)
28 DeleteFunc func(ctx context.Context, docID string, options driver.Options) (newRev string, err error)
29 StatsFunc func(ctx context.Context) (*driver.DBStats, error)
30 CompactFunc func(ctx context.Context) error
31 CompactViewFunc func(ctx context.Context, ddocID string) error
32 ViewCleanupFunc func(ctx context.Context) error
33 ChangesFunc func(ctx context.Context, options driver.Options) (driver.Changes, error)
34 PutAttachmentFunc func(ctx context.Context, docID string, att *driver.Attachment, options driver.Options) (newRev string, err error)
35 GetAttachmentFunc func(ctx context.Context, docID, filename string, options driver.Options) (*driver.Attachment, error)
36 DeleteAttachmentFunc func(ctx context.Context, docID, filename string, options driver.Options) (newRev string, err error)
37 QueryFunc func(context.Context, string, string, driver.Options) (driver.Rows, error)
38 CloseFunc func() error
39 }
40
41
42 type DocCreator struct {
43 DB
44 CreateDocFunc func(ctx context.Context, doc interface{}, options driver.Options) (docID, rev string, err error)
45 }
46
47
48 func (db *DocCreator) CreateDoc(ctx context.Context, doc interface{}, opts driver.Options) (string, string, error) {
49 return db.CreateDocFunc(ctx, doc, opts)
50 }
51
52
53 type SecurityDB struct {
54 DB
55 SecurityFunc func(ctx context.Context) (*driver.Security, error)
56 SetSecurityFunc func(ctx context.Context, security *driver.Security) error
57 }
58
59
60 func (db *DB) Get(ctx context.Context, docID string, opts driver.Options) (*driver.Document, error) {
61 return db.GetFunc(ctx, docID, opts)
62 }
63
64 var _ driver.DB = &DB{}
65
66
67 func (db *DB) AllDocs(ctx context.Context, options driver.Options) (driver.Rows, error) {
68 return db.AllDocsFunc(ctx, options)
69 }
70
71
72 func (db *DB) Put(ctx context.Context, docID string, doc interface{}, opts driver.Options) (string, error) {
73 return db.PutFunc(ctx, docID, doc, opts)
74 }
75
76
77 func (db *DB) Delete(ctx context.Context, docID string, opts driver.Options) (string, error) {
78 return db.DeleteFunc(ctx, docID, opts)
79 }
80
81
82 func (db *DB) Stats(ctx context.Context) (*driver.DBStats, error) {
83 return db.StatsFunc(ctx)
84 }
85
86
87 func (db *DB) Compact(ctx context.Context) error {
88 return db.CompactFunc(ctx)
89 }
90
91
92 func (db *DB) CompactView(ctx context.Context, docID string) error {
93 return db.CompactViewFunc(ctx, docID)
94 }
95
96
97 func (db *DB) ViewCleanup(ctx context.Context) error {
98 return db.ViewCleanupFunc(ctx)
99 }
100
101
102 func (db *SecurityDB) Security(ctx context.Context) (*driver.Security, error) {
103 return db.SecurityFunc(ctx)
104 }
105
106
107 func (db *SecurityDB) SetSecurity(ctx context.Context, security *driver.Security) error {
108 return db.SetSecurityFunc(ctx, security)
109 }
110
111
112 func (db *DB) Changes(ctx context.Context, opts driver.Options) (driver.Changes, error) {
113 return db.ChangesFunc(ctx, opts)
114 }
115
116
117 func (db *DB) PutAttachment(ctx context.Context, docID string, att *driver.Attachment, opts driver.Options) (string, error) {
118 return db.PutAttachmentFunc(ctx, docID, att, opts)
119 }
120
121
122 func (db *DB) GetAttachment(ctx context.Context, docID, filename string, opts driver.Options) (*driver.Attachment, error) {
123 return db.GetAttachmentFunc(ctx, docID, filename, opts)
124 }
125
126
127 func (db *DB) DeleteAttachment(ctx context.Context, docID, filename string, opts driver.Options) (string, error) {
128 return db.DeleteAttachmentFunc(ctx, docID, filename, opts)
129 }
130
131
132 func (db *DB) Query(ctx context.Context, ddoc, view string, opts driver.Options) (driver.Rows, error) {
133 return db.QueryFunc(ctx, ddoc, view, opts)
134 }
135
136
137 type OpenRever struct {
138 *DB
139 OpenRevsFunc func(context.Context, string, []string, driver.Options) (driver.Rows, error)
140 }
141
142 var _ driver.OpenRever = (*OpenRever)(nil)
143
144
145 func (db *OpenRever) OpenRevs(ctx context.Context, docID string, revs []string, options driver.Options) (driver.Rows, error) {
146 return db.OpenRevsFunc(ctx, docID, revs, options)
147 }
148
149
150 type Finder struct {
151 *DB
152 CreateIndexFunc func(context.Context, string, string, interface{}, driver.Options) error
153 DeleteIndexFunc func(context.Context, string, string, driver.Options) error
154 FindFunc func(context.Context, interface{}, driver.Options) (driver.Rows, error)
155 GetIndexesFunc func(context.Context, driver.Options) ([]driver.Index, error)
156 ExplainFunc func(context.Context, interface{}, driver.Options) (*driver.QueryPlan, error)
157 }
158
159 var _ driver.Finder = &Finder{}
160
161
162 func (db *Finder) CreateIndex(ctx context.Context, ddoc, name string, index interface{}, options driver.Options) error {
163 return db.CreateIndexFunc(ctx, ddoc, name, index, options)
164 }
165
166
167 func (db *Finder) DeleteIndex(ctx context.Context, ddoc, name string, opts driver.Options) error {
168 return db.DeleteIndexFunc(ctx, ddoc, name, opts)
169 }
170
171
172 func (db *Finder) Find(ctx context.Context, query interface{}, opts driver.Options) (driver.Rows, error) {
173 return db.FindFunc(ctx, query, opts)
174 }
175
176
177 func (db *Finder) GetIndexes(ctx context.Context, opts driver.Options) ([]driver.Index, error) {
178 return db.GetIndexesFunc(ctx, opts)
179 }
180
181
182 func (db *Finder) Explain(ctx context.Context, query interface{}, opts driver.Options) (*driver.QueryPlan, error) {
183 return db.ExplainFunc(ctx, query, opts)
184 }
185
186
187 type Flusher struct {
188 *DB
189 FlushFunc func(context.Context) error
190 }
191
192 var _ driver.Flusher = &Flusher{}
193
194
195 func (db *Flusher) Flush(ctx context.Context) error {
196 return db.FlushFunc(ctx)
197 }
198
199
200 type RevGetter struct {
201 *DB
202 GetRevFunc func(context.Context, string, driver.Options) (string, error)
203 }
204
205 var _ driver.RevGetter = &RevGetter{}
206
207
208 func (db *RevGetter) GetRev(ctx context.Context, docID string, opts driver.Options) (string, error) {
209 return db.GetRevFunc(ctx, docID, opts)
210 }
211
212
213 type Copier struct {
214 *DB
215 CopyFunc func(context.Context, string, string, driver.Options) (string, error)
216 }
217
218 var _ driver.Copier = &Copier{}
219
220
221 func (db *Copier) Copy(ctx context.Context, target, source string, options driver.Options) (string, error) {
222 return db.CopyFunc(ctx, target, source, options)
223 }
224
225
226 type AttachmentMetaGetter struct {
227 *DB
228 GetAttachmentMetaFunc func(ctx context.Context, docID, filename string, options driver.Options) (*driver.Attachment, error)
229 }
230
231 var _ driver.AttachmentMetaGetter = &AttachmentMetaGetter{}
232
233
234 func (db *AttachmentMetaGetter) GetAttachmentMeta(ctx context.Context, docID, filename string, options driver.Options) (*driver.Attachment, error) {
235 return db.GetAttachmentMetaFunc(ctx, docID, filename, options)
236 }
237
238
239 type DesignDocer struct {
240 *DB
241 DesignDocsFunc func(context.Context, driver.Options) (driver.Rows, error)
242 }
243
244 var _ driver.DesignDocer = &DesignDocer{}
245
246
247 func (db *DesignDocer) DesignDocs(ctx context.Context, options driver.Options) (driver.Rows, error) {
248 return db.DesignDocsFunc(ctx, options)
249 }
250
251
252 type LocalDocer struct {
253 *DB
254 LocalDocsFunc func(context.Context, driver.Options) (driver.Rows, error)
255 }
256
257 var _ driver.LocalDocer = &LocalDocer{}
258
259
260 func (db *LocalDocer) LocalDocs(ctx context.Context, options driver.Options) (driver.Rows, error) {
261 return db.LocalDocsFunc(ctx, options)
262 }
263
264
265 type Purger struct {
266 *DB
267 PurgeFunc func(context.Context, map[string][]string) (*driver.PurgeResult, error)
268 }
269
270 var _ driver.Purger = &Purger{}
271
272
273 func (db *Purger) Purge(ctx context.Context, docMap map[string][]string) (*driver.PurgeResult, error) {
274 return db.PurgeFunc(ctx, docMap)
275 }
276
277
278 type BulkGetter struct {
279 *DB
280 BulkGetFunc func(context.Context, []driver.BulkGetReference, driver.Options) (driver.Rows, error)
281 }
282
283 var _ driver.BulkGetter = &BulkGetter{}
284
285
286 func (db *BulkGetter) BulkGet(ctx context.Context, docs []driver.BulkGetReference, opts driver.Options) (driver.Rows, error) {
287 return db.BulkGetFunc(ctx, docs, opts)
288 }
289
290
291 func (db *DB) Close() error {
292 if db != nil && db.CloseFunc != nil {
293 return db.CloseFunc()
294 }
295 return nil
296 }
297
298
299 type RevsDiffer struct {
300 *BulkDocer
301 RevsDiffFunc func(context.Context, interface{}) (driver.Rows, error)
302 }
303
304 var _ driver.RevsDiffer = &RevsDiffer{}
305
306
307 func (db *RevsDiffer) RevsDiff(ctx context.Context, revMap interface{}) (driver.Rows, error) {
308 return db.RevsDiffFunc(ctx, revMap)
309 }
310
311
312 type PartitionedDB struct {
313 *DB
314 PartitionStatsFunc func(context.Context, string) (*driver.PartitionStats, error)
315 }
316
317
318 func (db *PartitionedDB) PartitionStats(ctx context.Context, name string) (*driver.PartitionStats, error) {
319 return db.PartitionStatsFunc(ctx, name)
320 }
321
View as plain text