|
306 | 306 |
|
307 | 307 | ;;; ## order-by
|
308 | 308 |
|
309 |
| -(s/defn ^:private ^:always-validate maybe-parse-order-by-subclause :- i/OrderBy [subclause] |
310 |
| - (cond |
311 |
| - (map? subclause) subclause |
312 |
| - (vector? subclause) (let [[f direction] subclause] |
313 |
| - (log/warn (u/format-color 'yellow (str "The syntax for order-by has changed in MBQL '98. [<field> :ascending/:descending] is deprecated. " |
314 |
| - "Prefer [:asc/:desc <field>] instead."))) |
315 |
| - {:field (field f), :direction (normalize-token direction)}))) |
316 |
| - |
317 |
| -(s/defn ^:ql ^:always-validate asc :- i/OrderBy |
318 |
| - "order-by subclause. Specify that results should be returned in ascending order for Field or AgRef F. |
| 309 | +(s/defn ^:private ^:always-validate order-by-subclause :- i/OrderBy |
| 310 | + [direction :- i/OrderByDirection, f] |
| 311 | + ;; it's not particularly useful to sort datetime fields with the default `:day` bucketing, |
| 312 | + ;; so specifiy `:default` bucketing to prevent the default of `:day` from being set during resolution. |
| 313 | + ;; This won't affect fields that aren't `DateTimeFields`. |
| 314 | + {:direction direction |
| 315 | + :field (let [f (field f)] |
| 316 | + (if-not (instance? FieldPlaceholder f) |
| 317 | + f |
| 318 | + (update f :datetime-unit (fn [unit] |
| 319 | + (core/or unit :default)))))}) |
| 320 | + |
| 321 | +(def ^:ql ^{:arglists '([field])} asc |
| 322 | + "`order-by` subclause. Specify that results should be returned in ascending order for Field or AgRef F. |
319 | 323 |
|
320 | 324 | (order-by {} (asc 100))"
|
321 |
| - [f] |
322 |
| - {:field (field f), :direction :ascending}) |
| 325 | + (partial order-by-subclause :ascending)) |
323 | 326 |
|
324 |
| -(s/defn ^:ql ^:always-validate desc :- i/OrderBy |
325 |
| - "order-by subclause. Specify that results should be returned in ascending order for Field or AgRef F. |
| 327 | +(def ^:ql ^{:arglists '([field])} desc |
| 328 | + "`order-by` subclause. Specify that results should be returned in ascending order for Field or AgRef F. |
326 | 329 |
|
327 | 330 | (order-by {} (desc 100))"
|
328 |
| - [f] |
329 |
| - {:field (field f), :direction :descending}) |
| 331 | + (partial order-by-subclause :descending)) |
| 332 | + |
| 333 | +(s/defn ^:private ^:always-validate maybe-parse-order-by-subclause :- i/OrderBy |
| 334 | + [subclause] |
| 335 | + (cond |
| 336 | + (map? subclause) subclause ; already parsed by `asc` or `desc` |
| 337 | + (vector? subclause) (let [[f direction] subclause] |
| 338 | + (log/warn (u/format-color 'yellow "The syntax for order-by has changed in MBQL '98. [<field> :ascending/:descending] is deprecated. Prefer [:asc/:desc <field>] instead.")) |
| 339 | + (order-by-subclause (normalize-token direction) f)))) |
330 | 340 |
|
331 | 341 | (defn ^:ql order-by
|
332 | 342 | "Specify how ordering should be done for this query.
|
|
0 commit comments