mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
28 lines
512 B
Go
28 lines
512 B
Go
package utils
|
|
|
|
import (
|
|
"github.com/crawlab-team/crawlab-db/generic"
|
|
"github.com/upper/db/v4"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
func GetSqlQuery(query generic.ListQuery) (res db.Cond) {
|
|
res = db.Cond{}
|
|
for _, c := range query {
|
|
switch c.Value.(type) {
|
|
case primitive.ObjectID:
|
|
c.Value = c.Value.(primitive.ObjectID).Hex()
|
|
}
|
|
switch c.Op {
|
|
case generic.OpEqual:
|
|
res[c.Key] = c.Value
|
|
default:
|
|
res[c.Key] = db.Cond{
|
|
c.Op: c.Value,
|
|
}
|
|
}
|
|
}
|
|
// TODO: sort
|
|
return res
|
|
}
|