Last active
October 24, 2017 16:18
-
-
Save bluemont/5561280 to your computer and use it in GitHub Desktop.
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 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