-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitf.go
76 lines (61 loc) · 2.29 KB
/
itf.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
package morm
import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
type ModelI interface {
CreateIndex(m interface{}, i mongo.IndexModel, opt *options.CreateIndexesOptions) (string, error)
Create(d interface{}) (*mongo.InsertOneResult, error)
CreateMany(d interface{}, r []interface{}) (*mongo.InsertManyResult, error)
FindOne(d interface{}) error
FindOneBy(d, q interface{}) error
FindManyBy(d, q interface{}, o *options.FindOptions) (*mongo.Cursor, error)
CountBy(d, q interface{}) (int64, error)
UpdateOne(d interface{}) (*mongo.UpdateResult, error)
UpdateOneBy(d, q, s interface{}, o *options.UpdateOptions) (*mongo.UpdateResult, error)
UpdateManyBy(d, q, s interface{}, o *options.UpdateOptions) (*mongo.UpdateResult, error)
DeleteOne(d interface{}) (*mongo.DeleteResult, error)
DeleteBy(d, q interface{}) (*mongo.DeleteResult, error)
DistinctBy(d interface{}, f string, ft bson.D) ([]interface{}, error)
}
// DistinctBy 按字段查唯一集
func DistinctBy(m ModelI, f string, ft bson.D) ([]interface{}, error) {
return m.DistinctBy(m, f, ft)
}
func CreateIndex(m ModelI, i mongo.IndexModel, opt *options.CreateIndexesOptions) (string, error) {
return m.CreateIndex(m, i, opt)
}
func FindOne(m ModelI) error {
return m.FindOne(m)
}
func FindOneBy(m ModelI, q interface{}) error {
return m.FindOneBy(m, q)
}
func FindManyBy(m ModelI, q interface{}, o *options.FindOptions) (*mongo.Cursor, error) {
return m.FindManyBy(m, q, o)
}
func CountBy(m ModelI, q interface{}) (int64, error) {
return m.CountBy(m, q)
}
func UpdateOne(m ModelI) (*mongo.UpdateResult, error) {
return m.UpdateOne(m)
}
func UpdateOneBy(m ModelI, q, s interface{}, o *options.UpdateOptions) (*mongo.UpdateResult, error) {
return m.UpdateOneBy(m, q, s, o)
}
func UpdateManyBy(m ModelI, q, s interface{}, o *options.UpdateOptions) (*mongo.UpdateResult, error) {
return m.UpdateManyBy(m, q, s, o)
}
func Create(m ModelI) (*mongo.InsertOneResult, error) {
return m.Create(m)
}
func CreateMany(m ModelI, d []interface{}) (*mongo.InsertManyResult, error) {
return m.CreateMany(m, d)
}
func DeleteOne(m ModelI) (*mongo.DeleteResult, error) {
return m.DeleteOne(m)
}
func DeleteBy(m ModelI, q interface{}) (*mongo.DeleteResult, error) {
return m.DeleteBy(m, q)
}