Created
August 27, 2012 14:05
-
-
Save martintrojer/3488729 to your computer and use it in GitHub Desktop.
org.clojure/java.jdbc
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 jdbc.core | |
(:require [clojure.java.jdbc :as jdbc])) | |
(def db-spec {:classname "org.sqlite.JDBC" | |
:subprotocol "sqlite" | |
:subname "test.db"}) | |
(jdbc/with-connection db-spec | |
(jdbc/create-table :authors | |
[:id "integer primary key"] | |
[:first_name "varchar"] | |
[:last_name "varchar"])) | |
(jdbc/with-connection db-spec | |
(jdbc/insert-records :authors | |
{:first_name "Chas" :last_name "Emerick"} | |
{:first_name "Christophe" :last_name "Grand"} | |
{:first_name "Brian" :last_name "Carper"})) | |
(jdbc/with-connection db-spec | |
(jdbc/with-query-results res ["SELECT * FROM authors"] | |
(doall res))) | |
(jdbc/with-connection db-spec | |
(jdbc/with-query-results res ["SELECT * FROM authors WHERE id = ?" 2] | |
(doall res))) | |
(jdbc/with-connection db-spec (jdbc/transaction | |
(jdbc/delete-rows :authors ["id = ?" 1]) | |
(throw (Exception. "Abort transaction!")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment