-
-
Save mefesto/470904 to your computer and use it in GitHub Desktop.
This file contains 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 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