-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpl.go
75 lines (60 loc) · 1.35 KB
/
impl.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
package mongo
import (
mgo "gopkg.in/mgo.v2"
)
// NewSession will create a new Session using an mgo.Session and a default Database
func NewSession(session *mgo.Session, databaseName string) Session {
return &sessionImpl{
Session: session,
DatabaseName: databaseName,
}
}
type sessionImpl struct {
Session *mgo.Session
DatabaseName string
}
func (s *sessionImpl) Copy() Session {
return &sessionImpl{
Session: s.Session.Copy(),
DatabaseName: s.DatabaseName,
}
}
func (s *sessionImpl) DB(name string) Database {
return &databaseImpl{
Database: s.Session.DB(name),
}
}
func (s *sessionImpl) DatabaseNames() ([]string, error) {
return s.Session.DatabaseNames()
}
func (s *sessionImpl) DefaultDB() Database {
return s.DB(s.DatabaseName)
}
func (s *sessionImpl) Close() {
s.Session.Close()
}
type databaseImpl struct {
*mgo.Database
}
func (d *databaseImpl) C(name string) Collection {
return &collectionImpl{
Collection: d.Database.C(name),
}
}
func (d *databaseImpl) DropDatabase() error {
return d.Database.DropDatabase()
}
type collectionImpl struct {
*mgo.Collection
}
func (c *collectionImpl) Find(query interface{}) Query {
return queryImpl{
Query: c.Collection.Find(query),
}
}
func (c *collectionImpl) Insert(docs ...interface{}) error {
return c.Collection.Insert(docs...)
}
type queryImpl struct {
*mgo.Query
}