-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivity.go
42 lines (35 loc) · 999 Bytes
/
activity.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
package stores
import (
"context"
"github.com/sol-armada/sol-bot/utils"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
type ActivityStore struct {
*store
}
const ACTIVITY Collection = "activity"
func newActivityStore(ctx context.Context, client *mongo.Client, database string) *ActivityStore {
_ = client.Database(database).CreateCollection(ctx, string(ACTIVITY), &options.CreateCollectionOptions{
TimeSeriesOptions: &options.TimeSeriesOptions{
TimeField: "when",
MetaField: utils.StringPointer("meta"),
},
})
s := &store{
Collection: client.Database(database).Collection(string(ACTIVITY)),
ctx: ctx,
}
return &ActivityStore{s}
}
func (c *Client) GetActivityStore() (*ActivityStore, bool) {
storeInterface, ok := c.GetCollection(ACTIVITY)
if !ok {
return nil, false
}
return storeInterface.(*ActivityStore), ok
}
func (s *ActivityStore) Create(activity any) error {
_, err := s.InsertOne(s.ctx, activity)
return err
}