-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructure.go
112 lines (94 loc) · 2.38 KB
/
structure.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
package gomongo
import (
mgo "github.com/globalsign/mgo"
"github.com/globalsign/mgo/bson"
)
type Callback struct {
Data interface{}
Error error
}
type DB interface {
Connect(*Config) (*Connection, error)
}
type Operations interface {
BulkInsertStruct(*BulkInsertStruct)
Insert(*InsertStruct) error
InsertAsync(*InsertStruct, *Callback)
Update(*UpdateStruct) error
UpdateAsync(*UpdateStruct, *Callback)
Upsert(*UpsertStruct) (*mgo.ChangeInfo, error)
UpsertAsync(*UpsertStruct, *Callback)
UpdateAll(*UpdateAllStruct) (*mgo.ChangeInfo, error)
UpdateAllAsync(*UpdateAllStruct, *Callback)
UpsertAll(*UpsertAllStruct) (*mgo.ChangeInfo, error)
UpsertAllAsync(*UpsertAllStruct, *Callback)
FindByID(*FindByIDStruct) (interface{}, error)
FindByIDAsync(*FindByIDStruct, *Callback)
Find(*FindStruct) ([]interface{}, error)
FindAsync(*FindStruct, *Callback)
FindAll(*FindAllStruct) ([]interface{}, error)
FindAllAsync(*FindAllStruct, *Callback)
Remove(*RemoveStruct) error
RemoveAsync(*RemoveStruct, *Callback)
RemoveAll(*RemoveAllStruct) (*mgo.ChangeInfo, error)
RemoveAllAsync(*RemoveAllStruct, *Callback)
}
type Connection struct {
Database string //database name
DialInfo *mgo.DialInfo // connection info
Session *mgo.Session //session info
Collections map[string]*mgo.Collection //all collections
Collection string //collection name
}
type Config struct {
Uri string
DbType string
Hosts string //connection url i.e, localhost:27017
Database string //database name
ReplicaSetName string //database name
Username string //username
Password string //password
AuthDatabase string //auth db
Direct bool
}
type BulkInsertStruct struct {
Config *Config
Data []interface{}
}
type InsertStruct struct {
Data interface{}
}
type UpdateStruct struct {
Id string
Data interface{}
}
type UpsertStruct struct {
Id string
Data interface{}
}
type UpdateAllStruct struct {
Query bson.M
Data interface{}
}
type UpsertAllStruct struct {
Query bson.M
Data interface{}
}
type FindByIDStruct struct {
Id string
Fields bson.M
}
type FindStruct struct {
Query bson.M
Options map[string]int
Fields bson.M
}
type FindAllStruct struct {
Fields bson.M
}
type RemoveStruct struct {
Query bson.M
}
type RemoveAllStruct struct {
}
type MongoDB struct{}