Created
September 25, 2012 19:18
-
-
Save toby/3783867 to your computer and use it in GitHub Desktop.
Lazy select with Korma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns something.cool | |
(:use [korma.core])) | |
(def page-size 20) | |
(defn lazy-select | |
"Creates a lazy sequence of sql results by batch selecting." | |
([statement] | |
(lazy-select statement 0)) | |
([statement o] | |
(when-let [r (seq (select (-> statement | |
(limit page-size) | |
(offset o))))] | |
(lazy-cat r (lazy-select statement (+ o page-size)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment