Clojure The jdbc create-table statement does not start if Leiningen REPL is not used

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.

+7
source share
1 answer

This is a general HSQLDB configuration issue.

The default HSQLDB configuration is not intended for use in tests. As a result, it delays the recording and synchronization of .log entries by 500 milliseconds, and it does not shut down the database when the connection is closed. Try these settings in your url:

 :subname "file:/tmp/tramwaydb;hsqldb.write_delay=false" 

or

 :subname "file:/tmp/tramwaydb;shutdown=true" 

See various options here: http://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html

+7
source

All Articles