(pathItem string, values map[string]interface{}, beforeFunctions []functionInfo)
| 135 | } |
| 136 | |
| 137 | func resolveOperationValues(pathItem string, values map[string]interface{}, beforeFunctions []functionInfo) (map[string]string, error) { |
| 138 | dbItem, err := newResolveDB(pathItem) |
| 139 | if err != nil { |
| 140 | return nil, err |
| 141 | } |
| 142 | defer closeResolveDB(dbItem) |
| 143 | |
| 144 | resolved := make(map[string]string) |
| 145 | for _, funcs := range beforeFunctions { |
| 146 | if !isSafeIdentifier(funcs.DB) || !isSafeIdentifier(funcs.InputColumn) || !isSafeIdentifier(funcs.OutputColumn) { |
| 147 | continue |
| 148 | } |
| 149 | for key, value := range values { |
| 150 | if funcs.InputValue != key { |
| 151 | continue |
| 152 | } |
| 153 | var names []string |
| 154 | if funcs.IsList { |
| 155 | sql := fmt.Sprintf("SELECT %s FROM %s where %s in (?);", funcs.OutputColumn, funcs.DB, funcs.InputColumn) |
| 156 | _ = dbItem.Raw(sql, value).Scan(&names) |
| 157 | } else { |
| 158 | sql := fmt.Sprintf("SELECT %s FROM %s where %s = ?;", funcs.OutputColumn, funcs.DB, funcs.InputColumn) |
| 159 | _ = dbItem.Raw(sql, value).Scan(&names) |
| 160 | } |
| 161 | outputValue := strings.Join(names, ",") |
| 162 | resolved[funcs.OutputValue] = outputValue |
| 163 | values[funcs.OutputValue] = outputValue |
| 164 | break |
| 165 | } |
| 166 | } |
| 167 | return resolved, nil |
| 168 | } |
| 169 | |
| 170 | func newResolveDB(pathItem string) (*gorm.DB, error) { |
| 171 | dbFile := "" |
no test coverage detected