-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdal.go
More file actions
69 lines (57 loc) · 1.19 KB
/
dal.go
File metadata and controls
69 lines (57 loc) · 1.19 KB
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
package dal
import (
"errors"
"time"
)
var ErrNotFound = errors.New("ErrNotFound")
type Q map[string]interface{}
type DAL interface {
Connect(string) (Connection, error)
IsObjectIdHex(string) bool
}
type Connection interface {
Clone() Connection
Close()
DB(s string) Database
}
type Database interface {
C(string) Collection
}
type Collection interface {
Find(Q) Query
EnsureIndex(Index) error
FindID(interface{}) Query
RemoveID(interface{}) error
UpsertID(interface{}, interface{}) (*ChangeInfo, error)
Upsert(interface{}, interface{}) (*ChangeInfo, error)
Insert(...interface{}) error
Save(interface{}, interface{}) (*ChangeInfo, error)
SaveID(interface{}, interface{}) (*ChangeInfo, error)
}
type Query interface {
One(interface{}) error
All(interface{}) error
Sort(...string) Query
Iter() Iter
Apply(Change, interface{}) (*ChangeInfo, error)
}
type Iter interface {
Next(interface{}) bool
}
type Index struct {
Key []string
Background bool
Sparse bool
ExpireAfter time.Duration
}
type ChangeInfo struct {
Updated int
Removed int
UpsertedId interface{}
}
type Change struct {
Update interface{}
Upsert bool
Remove bool
ReturnNew bool
}