Skip to content
Browse files

Added db

  • Loading branch information...
1 parent ee24190 commit 4080c505a2688670617cd5ad4496b946d3f2ded8 @zolrath committed
BIN resources/public/img/.DS_Store
Binary file not shown.
BIN resources/public/img/certs/aplus.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 src/andrew_site/models/.#db.clj
39 src/andrew_site/models/db.clj
@@ -0,0 +1,39 @@
+(ns andrew-site.models.db
+ (:use noir.core
+ hiccup.core
+ somnium.congomongo
+ [somnium.congomongo.config :only [*mongo-config*]]))
+(defn split-mongo-url [url]
+ "Parses mongodb url from heroku, eg. mongodb://user:pass@localhost:1234/db"
+ (let [matcher (re-matcher #"^.*://(.*?):(.*?)@(.*?):(\d+)/(.*)$" url)] ;; Setup the regex.
+ (when (.find matcher) ;; Check if it matches.
+ (zipmap [:match :user :pass :host :port :db] (re-groups matcher))))) ;; Construct an options map.
+(defn maybe-init []
+ "Checks if connection and collection exist, otherwise initialize."
+ (when (not (connection? *mongo-config*)) ;; If global connection doesn't exist yet.
+ (let [mongo-url (get (System/getenv) "MONGOHQ_URL") ;; Heroku puts it here.
+ config (split-mongo-url mongo-url)] ;; Extract options.
+ (println "Initializing mongo @ " mongo-url)
+ (mongo! :db (:db config) :host (:host config) :port (Integer. (:port config))) ;; Setup global mongo.
+ (authenticate (:user config) (:pass config)) ;; Setup u/p.)))
+(def major-skills
+ (map #(:skill %) (fetch :skills :where {:level "major"})))
+(def lesser-skills
+ (map #(:skill %) (fetch :skills :where {:level "lesser"})))
+(defn add-major-skill [skill]
+ (insert! :skills {:level "major" :skill skill}))
+(defn add-lesser-skill [skill]
+ (insert! :skills {:level "lesser" :skill skill}))
+(defn add-job [{:keys [name start-year end-year url description]}]
+ (insert! :jobs {:name name :start-year start-year :end-year end-year :url url :description description}))
+(def jobs
+ (fetch :jobs))
BIN src/andrew_site/views/.DS_Store
Binary file not shown.

0 comments on commit 4080c50

Please sign in to comment.
Something went wrong with that request. Please try again.