Created
August 17, 2014 22:01
-
-
Save matstani/4846ff717e4997139937 to your computer and use it in GitHub Desktop.
ringハンドラ内でDatabaseコンポーネントを利用
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 example-component-ring.handler | |
(:require [clojure.string :as str] | |
[compojure.core :refer :all] | |
[compojure.handler :as handler] | |
[compojure.route :as route] | |
[monger.collection :as mc] | |
[monger.core :as mg])) | |
(defn get-entries [{:keys [connection]}] | |
(let [db (mg/get-db connection "mydb")] | |
(mc/find db "entries" {}))) | |
(defn get-entry-list [db] | |
(let [entries (get-entries db)] | |
(str/join "<br />" (map #(get % "title") entries)))) | |
(defroutes app-routes | |
(GET "/" [:as {db :db}] (get-entry-list db)) | |
(route/resources "/") | |
(route/not-found "Not Found")) | |
(def app | |
(handler/site app-routes)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment