Created
February 2, 2009 05:39
-
-
Save pierrel/56794 to your computer and use it in GitHub Desktop.
How to use sqlite with clojure
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 something | |
(:require [clojure.contrib.sql :as sql])) | |
; Give the sql library all the information about the db | |
; to be used in transactions | |
(def db {:classname "org.sqlite.JDBC" | |
:subprotocol "sqlite" ; Protocol to use | |
:subname "db/db.sqlite3" ; Location of db | |
:create true}) | |
(. Class (forName "org.sqlite.JDBC")) ; Initialize the JDBC driver | |
(defn db-create | |
"Creates the table for this model" | |
[] | |
(sql/create-table | |
:something | |
[:id :int "PRIMARY KEY"] | |
[:name "varchar(32)"])) | |
(sql/with-connection | |
db | |
(sql/transaction | |
(db-create))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment