Files
crawlab/core/mongo/utils.go
Marvin Zhang dc59599509 refactor: remove db module and update imports to core/mongo
- Deleted the db module, consolidating database-related functionality into the core/mongo package for better organization and maintainability.
- Updated all import paths across the codebase to replace references to the removed db module with core/mongo.
- Cleaned up unused code and dependencies, enhancing overall project clarity and reducing complexity.
- This refactor improves the structure of the codebase by centralizing database operations and simplifying module management.
2024-12-25 10:28:21 +08:00

37 lines
683 B
Go

package mongo
import "go.mongodb.org/mongo-driver/bson"
func GetMongoQuery(query ListQuery) (res bson.M) {
res = bson.M{}
for _, c := range query {
switch c.Op {
case OpEqual:
res[c.Key] = c.Value
default:
res[c.Key] = bson.M{
c.Op: c.Value,
}
}
}
return res
}
func GetMongoOpts(opts *ListOptions) (res *FindOptions) {
var sort bson.D
for _, s := range opts.Sort {
direction := 1
if s.Direction == SortDirectionAsc {
direction = 1
} else if s.Direction == SortDirectionDesc {
direction = -1
}
sort = append(sort, bson.E{Key: s.Key, Value: direction})
}
return &FindOptions{
Skip: opts.Skip,
Limit: opts.Limit,
Sort: sort,
}
}