This file contains hidden or 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
| (defn collect* | |
| [table & xs] | |
| (if (vector? (last xs)) | |
| (let [tbls (interpose ", " (map #(sqlize %) (conj (butlast xs) table))) | |
| cols (str-utils/str-join ", " (map #(sqlize %) (last xs)))] | |
| (apply str "select " cols " from " tbls)) | |
| (let [tbls (interpose ", " (map #(sqlize %) (conj xs table)))] | |
| (apply str "select * from " tbls)))) | |
| (defmacro collect |
This file contains hidden or 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
| (sequel/filter (and (< :table1/a 5) (= :table1/b "x")) | |
| (sequel/collect :table1)) |
This file contains hidden or 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
| (sequel/filter (sequel/and | |
| (sequel/< :table1/a 5) | |
| (sequel/= :table1/b "x")) | |
| (sequel/collect :table1)) |
This file contains hidden or 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
| (filter (and (< :table1/a 5) (= :table1/b "x")) (collect :table1)) |
This file contains hidden or 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
| (-> (from :table1) | |
| (where (and (< :table1/a 5) (= :table1/b "x")))) |
This file contains hidden or 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 scale.core | |
| (:use compojure.core, ring.adapter.jetty, hiccup.core | |
| [clojure.contrib.sql :as sql]) | |
| (:import javax.sql.DataSource, org.postgresql.ds.PGPoolingDataSource)) | |
| (declare scale-app) | |
| (def rows-to-show 10) | |
| (def db-conn {:classname "org.postgresql.Driver" |
This file contains hidden or 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
| (def db-pool {:datasource (doto (new org.postgresql.ds.PGPoolingDataSource) | |
| (.setServerName "localhost") | |
| (.setDatabaseName "scale") | |
| (.setUser "scale") | |
| (.setPassword "scale") | |
| (.setMaxConnections 1))}) |
This file contains hidden or 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
| (def db-conn {:classname "org.postgresql.Driver" | |
| :subprotocol "postgresql" | |
| :subname "//localhost:5432/scale" | |
| :user "scale" | |
| :password "scale"}) |
This file contains hidden or 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
| (defmacro handle-failure | |
| [& forms] | |
| (let [[body handler] (split-with (complement handler-form?) forms) | |
| e# (symbol "errors")] | |
| `(kit/with-handler | |
| ~@body | |
| (kit/handle validation-error [~e#] | |
| ~@(rest (first handler)))))) |
This file contains hidden or 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
| (import 'org.apache.commons.mail.SimpleEmail) | |
| (doto (SimpleEmail.) | |
| (.setHostName "smtp.gmail.com") | |
| (.setSslSmtpPort "465") | |
| (.setSSL true) | |
| (.addTo "[email protected]") | |
| (.setFrom "[email protected]" "Lucky Clojurian") | |
| (.setSubject "Hello from clojure") | |
| (.setMsg "Wasn't that easy?") | |
| (.setAuthentication "[email protected]" "yourpassword") |