Created
November 28, 2011 18:46
-
-
Save ctataryn/1401486 to your computer and use it in GitHub Desktop.
Clojure Create Tables
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 my.ns | |
(:use [korma.db]) | |
(:use [korma.core]) | |
(:require [clojure.java.jdbc :as sql])) | |
(def dbspec {:classname "org.h2.Driver" | |
:subprotocol "h2" | |
:subname "~/db/myapp" | |
:user "sa" | |
:password ""}) | |
(defdb mydb dbspec) | |
(defentity factoid) | |
(defn create-tables | |
"Create a factoid table" | |
[] | |
(do | |
(sql/create-table | |
"factoid" | |
[:id "IDENTITY" "NOT NULL" "PRIMARY KEY"] | |
[:created_by "VARCHAR(255)"] | |
[:fact "VARCHAR(255)"] | |
[:answer "VARCHAR"] | |
[:created_on "TIMESTAMP" "NOT NULL" "DEFAULT CURRENT_TIMESTAMP"]) | |
(sql/do-commands "CREATE INDEX FACTIDX ON factoid(fact)"))) | |
(defn invoke-with-connection [f] | |
(sql/with-connection | |
dbspec | |
(sql/transaction | |
(f)))) | |
;; . | |
;; . | |
;; . | |
(invoke-with-connection create-tables) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome! Thanks for posting. Works great.