Skip to content

Instantly share code, notes, and snippets.

@mefesto
Forked from swannodette/postgres.clj
Created July 10, 2010 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mefesto/470904 to your computer and use it in GitHub Desktop.
Save mefesto/470904 to your computer and use it in GitHub Desktop.
(ns second-post.postgres
(: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 "org.postgresql.Driver")
(.setUrl "jdbc:postgresql://localhost/dummy")
(.setUsername "postgres")
(.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