I have a small Clojure program that uses Clojure JDBC tools to create a table in an HSQL database. However, it looks like a table is actually being created if I run it from the Leiningen REPL. It does not create a table if I run the code using lein run or from my IDE (IntelliJ). This is not reported. In both cases, the output is "(0)".
Here's the code snippet:
(ns tramway.core (:require [clojure.java.io :as io] [clojure.java.jdbc :as sql])) (def hsql-db {:subprotocol "hsqldb" :subname "file:/tmp/tramwaydb" :user "SA" :password ""}) (defn -main [] (println (sql/with-connection hsql-db (sql/create-table :footfall [:id "INTEGER" "GENERATED ALWAYS AS IDENTITY(START WITH 1)"] [:sample_date "DATE"] [:exhibition "varchar(255)"]))))
And since I use Leiningen, here is my project.clj :
(defproject tramway "1.0.0-SNAPSHOT" :description "Description here" :dependencies [[org.clojure/clojure "1.3.0"] [org.clojure/java.jdbc "0.1.4"] [org.hsqldb/hsqldb "2.2.8"]] :main tramway.core)
If I do this:
$ lein repl tramway.core=> (-main) (0) nil
and then check /tmp/tramway.log I see that CREATE TABLE is successful.
However, if I do this:
$ rm -rf /tmp/tramway.* $ lein run (0)
and then check the same file, it is empty. It creates .log , .properties and .script . All but the .log file have content; there is simply no entry for the CREATE TABLE that was running.
What am I doing wrong? I expect that I will have the same result, regardless of whether I run my function (-main) from REPL or automatically run Leiningen it.
I also tried to create a table from the -main function and run it as a script through my IDE, and I still get the same bad result.
Jonathan
source share