Skip to content

Instantly share code, notes, and snippets.

@kumarshantanu
Created August 31, 2010 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumarshantanu/558467 to your computer and use it in GitHub Desktop.
Save kumarshantanu/558467 to your computer and use it in GitHub Desktop.
(in-db db
(let [e (find-by-id blog-entry-meta 2)
r ((find-rels e entry-comment-meta) e)
rc ((find-rels e entry-comment-meta :cols [:content :name :email]) e)
rw ((find-rels e entry-comment-meta :where ["email=?" "hey@nospam.com"]) e)
rb ((find-rels e entry-comment-meta :cols [:content :name :email]
:where ["email=?" "hey@nospam.com"]) e)]
(ppe "\nEntry:" e)
(ppe "\nRelations:" r)
(ppe "\nRelations with selected columns:" rc)
(ppe "\nRelations with WHERE clause:" rw)
(ppe "\nRelations with selected columns and WHERE clause:" rb))
;; Avoiding N+1 selects
(let [entries (find-by-criteria blog-entry-meta)
comments (find-rels entries entry-comment-meta)]
(ppe "\nAll entries:" entries)
(doseq [each entries]
(ppe (str "\nComments for entry ID: " (:autoid each))
(comments each))))
;; Avoiding N+1 selects while counting
(let [entries (find-by-criteria blog-entry-meta)
comments (find-rels entries entry-comment-meta :cols count-col)]
(ppe "\nAll entries:" entries)
(doseq [each entries]
(println (str "\nComments# for entry ID: " (:autoid each))
(read-count-col (comments each))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment