Skip to content

Instantly share code, notes, and snippets.

@mefesto
Forked from swannodette/mysql.clj
Created July 10, 2010 17:58
Show Gist options
  • Select an option

  • Save mefesto/470901 to your computer and use it in GitHub Desktop.

Select an option

Save mefesto/470901 to your computer and use it in GitHub Desktop.
(ns second-post.mysql
(:use aleph)
(:require [clojure.contrib.sql :as sql])
(:import [org.apache.commons.dbcp BasicDataSource]))
(def pool-size 10) ; or match expected number of threads
(def ds
(doto (BasicDataSource.)
(.setDriverClassName "com.mysql.jdbc.Driver")
(.setUrl "jdbc:mysql://localhost:3306/dummy")
(.setUsername "root")
(.setPassword "")
(.setInitialSize pool-size)))
(def db {:datasource ds})
(defn insert-foo [val]
(sql/insert-values :foo [:bar] [val]))
(defn save [request]
(future
(sql/with-connection db (insert-foo "test"))
(respond! request
{:status 200
:headers {"Content-Type" "text/html"}
:body "Saved!"})))
(run-aleph save {:port 8080})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment