ResolveProjection resolves projection object and returns project sql statement and dependent fields.
(p map[string]interface{}, availFields FieldMap)
| 62 | |
| 63 | // ResolveProjection resolves projection object and returns project sql statement and dependent fields. |
| 64 | func ResolveProjection(p map[string]interface{}, availFields FieldMap) (fm FieldMap, statement string, err error) { |
| 65 | fm = FieldMap{} |
| 66 | var subStatements []string |
| 67 | |
| 68 | for k, v := range p { |
| 69 | if !availFields[k] { |
| 70 | err = errors.Errorf("unknown field: %s", k) |
| 71 | return |
| 72 | } |
| 73 | |
| 74 | if asBool(v) { |
| 75 | fm[k] = true |
| 76 | subStatements = append(subStatements, fmt.Sprintf(`"%s"`, k)) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if len(subStatements) == 0 { |
| 81 | for k := range availFields { |
| 82 | fm[k] = true |
| 83 | subStatements = append(subStatements, fmt.Sprintf(`"%s"`, k)) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | statement = strings.Join(subStatements, ",") |
| 88 | |
| 89 | return |
| 90 | } |
| 91 | |
| 92 | func logicRelation(childQueries []map[string]interface{}, availFields FieldMap, op string) ( |
| 93 | fields FieldMap, statement string, args []interface{}, err error) { |