Skip to content

Instantly share code, notes, and snippets.

@renatoalencar
Last active June 5, 2020 21:27
Show Gist options
  • Select an option

  • Save renatoalencar/655928b1d318255361dbb6413a5a9bef to your computer and use it in GitHub Desktop.

Select an option

Save renatoalencar/655928b1d318255361dbb6413a5a9bef to your computer and use it in GitHub Desktop.
Introducao a Clojure Component
(ns example-atom
(:require [ring.adapter.jetty :refer [run-jetty]]
[monger.core :as mg]
[monger.collection :as mc]))
(def database (atom nil))
(defn connect-db! [uri]
(swap! database (fn [db] (-> uri
mg/connect-via-uri
:db))))
(defn list-users! []
(mc/find-maps @database :users))
(defn handler [request]
{:status 200
:body (clojure.string/join "\n" (list-users!))})
(defn -main
[& args]
(connect-db! (System/getenv "DATABASE_URL"))
(run-jetty handler {:port 3000}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment