Skip to content

Instantly share code, notes, and snippets.

@ctataryn
Created November 28, 2011 18:46
Show Gist options
  • Select an option

  • Save ctataryn/1401486 to your computer and use it in GitHub Desktop.

Select an option

Save ctataryn/1401486 to your computer and use it in GitHub Desktop.
Clojure Create Tables
(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)
@troyastorino

Copy link
Copy Markdown

Awesome! Thanks for posting. Works great.

@ctataryn

ctataryn commented Dec 2, 2011

Copy link
Copy Markdown
Author

No prob, enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment