|
10 | 10 | [floor-plan {:keys [dispatch-key]}] |
11 | 11 | (get-in floor-plan [:target-table dispatch-key])) |
12 | 12 |
|
13 | | -(defn target-column |
| 13 | +(defn target-columns |
14 | 14 | [floor-plan {:keys [dispatch-key]}] |
15 | | - (get-in floor-plan [:target-column dispatch-key])) |
| 15 | + (get-in floor-plan [:target-columns dispatch-key])) |
16 | 16 |
|
17 | | -(defn source-column |
| 17 | +(defn source-columns |
18 | 18 | [floor-plan {:keys [dispatch-key]}] |
19 | | - (get-in floor-plan [:source-column dispatch-key])) |
| 19 | + (get-in floor-plan [:source-columns dispatch-key])) |
20 | 20 |
|
21 | 21 | (defn result-key [ast] |
22 | 22 | (let [k (:pathom/as (:params ast))] |
|
138 | 138 |
|
139 | 139 | (defn process-children* |
140 | 140 | "Infers which columns to include in SQL query from child keys in ast" |
141 | | - [floor-plan ast] |
| 141 | + [floor-plan ast] |
142 | 142 | (let [all-children (:children ast) |
143 | | - |
| 143 | + |
144 | 144 | {:keys [columns joins]} |
145 | 145 | (group-by #(keyword-type floor-plan %) all-children) |
146 | 146 |
|
147 | 147 | child-column-keys |
148 | 148 | (into #{} (map :dispatch-key) columns) |
149 | 149 |
|
150 | 150 | child-source-columns |
151 | | - (into #{} (map #(source-column floor-plan %)) joins)] |
| 151 | + (into #{} (mapcat #(source-columns floor-plan %)) joins)] |
152 | 152 | {:columns-to-query (set/union child-column-keys child-source-columns)})) |
153 | 153 |
|
154 | 154 | (defn process-children |
|
184 | 184 | (defn individual-query-template |
185 | 185 | [{:keys [floor-plan ast pagination]}] |
186 | 186 | (let [ident? (vector? (:key ast)) |
187 | | - |
| 187 | + |
188 | 188 | {:keys [:columns-to-query]} (process-children floor-plan ast) |
189 | | - target-column (target-column floor-plan ast) |
| 189 | + |
| 190 | + target-columns (target-columns floor-plan ast) |
190 | 191 |
|
191 | 192 | {:keys [:offset :limit :order-by :order-by-columns]} |
192 | 193 | (when-not ident? pagination) |
193 | 194 |
|
194 | 195 | columns-to-query |
195 | | - (-> (clojure.set/union columns-to-query order-by-columns) |
196 | | - (conj-some target-column)) |
| 196 | + (clojure.set/union columns-to-query order-by-columns (set target-columns)) |
197 | 197 |
|
198 | 198 | selection |
199 | 199 | (process-selection floor-plan columns-to-query) |
|
204 | 204 |
|
205 | 205 | sql-query {:raw-string |
206 | 206 | (emitter/->query-string |
207 | | - {:target-table (target-table floor-plan ast) |
208 | | - :join-statement (join-statement floor-plan ast) |
209 | | - :selection (:raw-string selection) |
210 | | - :conditions (:raw-string conditions) |
211 | | - ;; TODO: |
212 | | - ;; use :raw-string/:params here in case there are variables in group-by columns |
213 | | - :group-by (compiled-group-by floor-plan ast) |
214 | | - :having (:raw-string having) |
215 | | - :offset offset |
216 | | - :limit limit |
217 | | - :order-by order-by}) |
| 207 | + {:target-table (target-table floor-plan ast) |
| 208 | + :join-statement (join-statement floor-plan ast) |
| 209 | + :selection (:raw-string selection) |
| 210 | + :conditions (:raw-string conditions) |
| 211 | + ;; TODO: |
| 212 | + ;; use :raw-string/:params here in case there are variables in group-by columns |
| 213 | + :group-by (compiled-group-by floor-plan ast) |
| 214 | + :having (:raw-string having) |
| 215 | + :offset offset |
| 216 | + :limit limit |
| 217 | + :order-by order-by}) |
218 | 218 | :params (expressions/combine-params selection conditions having)}] |
219 | 219 | sql-query)) |
220 | 220 |
|
|
223 | 223 | [shared-query batched-individuals])) |
224 | 224 |
|
225 | 225 | #_(defn combine-without-cte [{:keys [batched-individuals]}] |
226 | | - batched-individuals) |
227 | | - |
228 | | -(defn source-column-variable-values |
229 | | - [v] |
230 | | - {:variable-values {`floor-plan/source-column-value |
231 | | - (expressions/compile-to-string {} v)}}) |
| 226 | + batched-individuals) |
232 | 227 |
|
233 | 228 | (defn compute-graphs [floor-plan env variables] |
234 | 229 | (let [variable->graph-index (variable->graph-index floor-plan) |
|
327 | 322 | (let [q (batched-individuals env entities)] |
328 | 323 | (when (not-empty (:raw-string q)) |
329 | 324 | (->> q |
330 | | - (process-query floor-plan env) |
331 | | - eliminate-unknown-variables)))))) |
| 325 | + (process-query floor-plan env) |
| 326 | + eliminate-unknown-variables)))))) |
332 | 327 |
|
333 | 328 | (defn prepare-query |
334 | 329 | [floor-plan ast] |
|
0 commit comments