mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
- 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.
37 lines
683 B
Go
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,
|
|
}
|
|
}
|