dbs and
This commit is contained in:
parent
d0e2778246
commit
e9dd17ae87
43
dbs/dbs.go
43
dbs/dbs.go
@ -35,26 +35,49 @@ func (m Operator) String() string {
|
|||||||
return str[m]
|
return str[m]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Operator) ToMongoOperator() string {
|
func (m Operator) ToMongoEOperator(k string, value interface{}) bson.E {
|
||||||
switch m {
|
switch m {
|
||||||
case LIKE:
|
case LIKE:
|
||||||
return "$regex"
|
return bson.E{Key: k, Value: bson.M{"$regex": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case EXISTS:
|
case EXISTS:
|
||||||
return "$exists"
|
return bson.E{Key: k, Value: bson.M{"$exists": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case IN:
|
case IN:
|
||||||
return "$in"
|
return bson.E{Key: k, Value: bson.M{"$in": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case GTE:
|
case GTE:
|
||||||
return "$gte"
|
return bson.E{Key: k, Value: bson.M{"$gte": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case GT:
|
case GT:
|
||||||
return "$gt"
|
return bson.E{Key: k, Value: bson.M{"$gt": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case LTE:
|
case LTE:
|
||||||
return "$lte"
|
return bson.E{Key: k, Value: bson.M{"$lte": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case LT:
|
case LT:
|
||||||
return "$lt"
|
return bson.E{Key: k, Value: bson.M{"$lt": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
case EQUAL:
|
case EQUAL:
|
||||||
return "$match"
|
return bson.E{Key: k, Value: value}
|
||||||
default:
|
default:
|
||||||
return "$regex"
|
return bson.E{Key: k, Value: bson.M{"$regex": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Operator) ToMongoOperator(k string, value interface{}) bson.M {
|
||||||
|
switch m {
|
||||||
|
case LIKE:
|
||||||
|
return bson.M{k: bson.M{"$regex": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
|
case EXISTS:
|
||||||
|
return bson.M{k: bson.M{"$exists": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
|
case IN:
|
||||||
|
return bson.M{k: bson.M{"$in": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
|
case GTE:
|
||||||
|
return bson.M{k: bson.M{"$gte": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
|
case GT:
|
||||||
|
return bson.M{k: bson.M{"$gt": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
|
case LTE:
|
||||||
|
return bson.M{k: bson.M{"$lte": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
|
case LT:
|
||||||
|
return bson.M{k: bson.M{"$lt": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
|
case EQUAL:
|
||||||
|
return bson.M{k: value}
|
||||||
|
default:
|
||||||
|
return bson.M{k: bson.M{"$regex": ToValueOperator(StringToOperator(m.String()), value)}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,17 +267,13 @@ func (m *MongoDB) Search(filters *dbs.Filters, collection_name string) (*mongo.C
|
|||||||
f := bson.D{}
|
f := bson.D{}
|
||||||
if filters != nil {
|
if filters != nil {
|
||||||
for k, filter := range filters.Or {
|
for k, filter := range filters.Or {
|
||||||
orList = append(orList, bson.M{
|
orList = append(orList, dbs.StringToOperator(filter.Operator).ToMongoOperator(k, filter.Value))
|
||||||
k: bson.M{dbs.StringToOperator(filter.Operator).ToMongoOperator(): dbs.ToValueOperator(dbs.StringToOperator(filter.Operator), filter.Value)}})
|
|
||||||
}
|
}
|
||||||
if len(orList) > 0 {
|
if len(orList) > 0 {
|
||||||
f = bson.D{{"$or", orList}}
|
f = bson.D{{"$or", orList}}
|
||||||
}
|
}
|
||||||
for k, filter := range filters.And {
|
for k, filter := range filters.And {
|
||||||
f = append(f, bson.E{
|
f = append(f, dbs.StringToOperator(filter.Operator).ToMongoEOperator(k, filter.Value))
|
||||||
k, bson.M{
|
|
||||||
dbs.StringToOperator(filter.Operator).ToMongoOperator(): dbs.ToValueOperator(dbs.StringToOperator(filter.Operator), filter.Value),
|
|
||||||
}})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,8 +107,8 @@ func (wfa *workflowMongoAccessor) execute(workflow *Workflow) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
resource, _, err := accessor.Search(filters, "")
|
resource, _, err := accessor.Search(filters, "")
|
||||||
fmt.Println(resource)
|
|
||||||
if err == nil && len(resource) > 0 {
|
if err == nil && len(resource) > 0 {
|
||||||
|
fmt.Println(workflow.Processings, resource[0].GetID())
|
||||||
accessor.UpdateOne(&workspace.Workspace{
|
accessor.UpdateOne(&workspace.Workspace{
|
||||||
Active: true,
|
Active: true,
|
||||||
ResourceSet: resources.ResourceSet{
|
ResourceSet: resources.ResourceSet{
|
||||||
|
Loading…
Reference in New Issue
Block a user