Skip to content

Instantly share code, notes, and snippets.

@bluemont
Last active October 24, 2017 16:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluemont/5561280 to your computer and use it in GitHub Desktop.
Save bluemont/5561280 to your computer and use it in GitHub Desktop.
(ns whatever.core
(:gen-class)
(:import [java.sql SQLException])
(:require [clojure.java.jdbc :as jdbc]
[clojure.java.jdbc.sql :as sql]
[clojure.pprint :as pprint]))
(def app-name "whatever")
(def env "development")
(defn database-name
[env]
(str app-name "_" env))
(defn database-url
[env]
(str "postgresql://localhost:5432/" (database-name env)))
(defmacro try-sql
[& args]
`(try
(~@args)
(catch SQLException e#
(jdbc/print-sql-exception-chain e#))))
(defn create-table
[env name & specs]
(jdbc/with-connection
(database-url env)
(try-sql apply jdbc/create-table name specs)))
(defn create-samples-table
[env]
(create-table
env
:samples
[:uuid :uuid "PRIMARY KEY"]
[:title :varchar]
[:created_at :timestamp]
[:updated_at :timestamp]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment