Skip to content

Instantly share code, notes, and snippets.

@toby
Created September 25, 2012 19:18
Show Gist options
  • Save toby/3783867 to your computer and use it in GitHub Desktop.
Save toby/3783867 to your computer and use it in GitHub Desktop.
Lazy select with Korma
(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