(childQueries []map[string]interface{}, availFields FieldMap, op string)
| 90 | } |
| 91 | |
| 92 | func logicRelation(childQueries []map[string]interface{}, availFields FieldMap, op string) ( |
| 93 | fields FieldMap, statement string, args []interface{}, err error) { |
| 94 | fields = FieldMap{} |
| 95 | |
| 96 | if len(childQueries) == 0 { |
| 97 | err = errors.New("$and/$or operator needs non-empty array") |
| 98 | return |
| 99 | } |
| 100 | |
| 101 | var subStatements []string |
| 102 | |
| 103 | for _, cq := range childQueries { |
| 104 | var ( |
| 105 | childField FieldMap |
| 106 | childStatement string |
| 107 | childArgs []interface{} |
| 108 | ) |
| 109 | childField, childStatement, childArgs, err = ResolveFilter(cq, availFields) |
| 110 | if err != nil { |
| 111 | return |
| 112 | } |
| 113 | |
| 114 | if childStatement == "" { |
| 115 | continue |
| 116 | } |
| 117 | |
| 118 | fields.Merge(childField) |
| 119 | subStatements = append(subStatements, childStatement) |
| 120 | args = append(args, childArgs...) |
| 121 | } |
| 122 | |
| 123 | if len(subStatements) == 0 { |
| 124 | return |
| 125 | } |
| 126 | |
| 127 | statement = "(" + strings.Join(subStatements, ") "+op+" (") + ")" |
| 128 | return |
| 129 | } |
| 130 | |
| 131 | // ResolveFieldCondition resolves field condition object and returns as where condition statement. |
| 132 | func ResolveFieldCondition(field string, v interface{}) (statement string, args []interface{}, err error) { |
no test coverage detected