Skip to content

Instantly share code, notes, and snippets.

(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
(sequel/filter (and (< :table1/a 5) (= :table1/b "x"))
(sequel/collect :table1))
(sequel/filter (sequel/and
(sequel/< :table1/a 5)
(sequel/= :table1/b "x"))
(sequel/collect :table1))
(filter (and (< :table1/a 5) (= :table1/b "x")) (collect :table1))
(-> (from :table1)
(where (and (< :table1/a 5) (= :table1/b "x"))))
(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"
(def db-pool {:datasource (doto (new org.postgresql.ds.PGPoolingDataSource)
(.setServerName "localhost")
(.setDatabaseName "scale")
(.setUser "scale")
(.setPassword "scale")
(.setMaxConnections 1))})
(def db-conn {:classname "org.postgresql.Driver"
:subprotocol "postgresql"
:subname "//localhost:5432/scale"
:user "scale"
:password "scale"})
(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))))))
(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")