/
interface.go
97 lines (86 loc) · 2.33 KB
/
interface.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
package db
import "time"
// Session provides a subset of the functionality of the *mgo.Session
// type.
type Session interface {
Clone() Session
Copy() Session
Close()
DB(string) Database
Error() error
}
// Database provides a very limited subset of the mgo.DB type.
type Database interface {
Name() string
C(string) Collection
CreateCollection(coll string) (Collection, error)
DropDatabase() error
}
// Collection provides access to the common query functionality of the
// mgo.Collection type.
type Collection interface {
DropCollection() error
Pipe(interface{}) Aggregation
Find(interface{}) Query
FindId(interface{}) Query
Count() (int, error)
Insert(...interface{}) error
Upsert(interface{}, interface{}) (*ChangeInfo, error)
UpsertId(interface{}, interface{}) (*ChangeInfo, error)
Update(interface{}, interface{}) error
UpdateId(interface{}, interface{}) error
UpdateAll(interface{}, interface{}) (*ChangeInfo, error)
Remove(interface{}) error
RemoveId(interface{}) error
RemoveAll(interface{}) (*ChangeInfo, error)
Bulk() Bulk
}
type Query interface {
Count() (int, error)
Limit(int) Query
Select(interface{}) Query
Skip(n int) Query
Sort(...string) Query
// Hint tells the query which index to use. The input must be either the
// name of the index as a string or the index specification as a document.
Hint(interface{}) Query
Apply(Change, interface{}) (*ChangeInfo, error)
MaxTime(time.Duration) Query
Results
}
type Aggregation interface {
Hint(interface{}) Aggregation
MaxTime(time.Duration) Aggregation
Results
}
type Bulk interface {
Insert(...interface{})
Remove(...interface{})
RemoveAll(...interface{})
Update(...interface{})
UpdateAll(...interface{})
Upsert(...interface{})
Unordered()
Run() (*BulkResult, error)
}
type BulkResult struct {
Matched int
Modified int
}
// Iterator is a more narrow subset of mgo's Iter type that
// provides the opportunity to mock results, and avoids a strict
// dependency between mgo and migrations definitions.
type Iterator interface {
Next(interface{}) bool
Close() error
Err() error
}
// Results reflect the output of a database operation and is part of
// the query interface
type Results interface {
All(interface{}) error
One(interface{}) error
Iter() Iterator
}
// Document is, like bson.M, a wrapper for an un-ordered map type
type Document map[string]interface{}