           (reduce (fn [records# table#]
                     (let [found-records# (~exec-fn (sql-fn# table#))
                           updated-records# (concat records# found-records#)]
-                      (if (and (= 1 (:limit ~options))
-                               (seq updated-records#))
+                      (if (limit-reached? updated-records# ~options)
                         (reduced updated-records#)
                         updated-records#)))
                   []))))

  (when (and sort-exp (sequential? sort-exp))
    (= :desc (second sort-exp))))

; TODO: maybe extract the sql parts and move this to the partitioning namespace?
(defmacro with-partitioning
  [exec-fn table-name d-range options bindings & body]

                         (h/left-join [:reconciliations :r] [:= :r.id :i.reconciliation_id])
                         (adjust-select options)
                         (h/where (map->where criteria {:prefix "i"}))
                         (append-sort (if (:count options)
                                           options
                                           (merge
                                             {:sort [:i.transaction_date :i.index]}
                                             options)))
                         (append-limit options)))]
        (if (:count options)
          (-> result first vals first)
