Does anyone know how to inser an enumerated type using honeysql / jdbc-next? I don’t have any problem using jdbc-next
(jdbc/execute-one ["INSERT INTO processes(id, state) VALUES(?, ?);" uuid (jdbc/as-other "ready"))
But when I try something similar with honeysql:
(jdbc/execute-one (-> (insert-into :processes) (values [{:id uuid, :state (jdbc/as-other "ready")}]) sql/format))
I get : java.lang.AssertionError: Assert failed: Alias should have two parts["running"] (= 2 (count x))
In case it wasn’t clear, state
is an enum type column. E.g.,:
CREATE TYPE STATES AS ENUM ('ready', 'complete', 'error');
CREATE TABLE IF NOT EXISTS processes (
id UUID DEFAULT uuid_generate_v4(),
PRIMARY KEY (id),
state STATES);
what does the sql come out as when you do sql/format
?
It works for me btw
txi=> CREATE TYPE STATES AS ENUM ('ready', 'complete', 'error');
CREATE TYPE
txi=> CREATE TABLE IF NOT EXISTS processes (
txi(> id UUID DEFAULT uuid_generate_v4(),
txi(> PRIMARY KEY (id),
txi(> state STATES);
CREATE TABLE
txi=> select * from processes ;
┌──────────────────────────────────────┬───────┐
│ id │ state │
├──────────────────────────────────────┼───────┤
│ b94f550e-f058-41e2-bdb6-e5c09e3cbd38 │ ready │
└──────────────────────────────────────┴───────┘
(1 row)
user=> (def s (-> (insert-into :processes) (values [{:id #uuid "b94f550e-f058-41e2-bdb6-e5c09e3cbd38", :state (as-other "ready")}]) sql/format))
#'user/s
user=> (db/execute! s (:txi-db app-config))
{:next.jdbc/update-count 1}
@aneil.mallavar update to the latest next.jdbc version. That was fixed a few versions ago.
ooof. sorry.
& thanks.
@seancorfield - hmmm. I’m still seeing the issue. These are my dependencies:
[seancorfield/next.jdbc "1.1.613"]
[honeysql "1.0.444"]
@dharrigan When I try your code, I get:
(def s (-> (insert-into :processes) (values [{:id #uuid "b94f550e-f058-41e2-bdb6-e5c09e3cbd38", :state (as-other "ready")}]) sql/format))
Syntax error (AssertionError) compiling at (form-init15174950692797201891.clj:1:8).
Assert failed: Alias should have two parts["ready"]
(= 2 (count x))
I’m going to try with a fresh project.
If you're getting ["ready"] then you somehow are still using the older next JDBC. That behavior changed in 1.1.610
@aneil.mallavar Here's proof of the problem being fixed between 1.1.588 and 1.1.613:
seanc@DESKTOP-30ICA76:~/clojure$ clj -Sdeps '{:deps {honeysql/honeysql {:mvn/version "1.0.444"} seancorfield/next.jdbc {:mvn/version "1.1.613"}}}'
Clojure 1.10.1
user=> (require '[honeysql.core :as sql] '[honeysql.helpers :refer :all] '[next.jdbc.types :refer :all])
WARNING: update already refers to: #'clojure.core/update in namespace: user, being replaced by: #'honeysql.helpers/update
nil
user=> (def s (-> (insert-into :processes) (values [{:id #uuid "b94f550e-f058-41e2-bdb6-e5c09e3cbd38", :state (as-other "ready")}]) sql/format))
#'user/s
user=>
seanc@DESKTOP-30ICA76:~/clojure$ clj -Sdeps '{:deps {honeysql/honeysql {:mvn/version "1.0.444"} seancorfield/next.jdbc {:mvn/version "1.1.588"}}}'
Clojure 1.10.1
user=> (require '[honeysql.core :as sql] '[honeysql.helpers :refer :all] '[next.jdbc.types :refer :all])
WARNING: update already refers to: #'clojure.core/update in namespace: user, being replaced by: #'honeysql.helpers/update
nil
user=> (def s (-> (insert-into :processes) (values [{:id #uuid "b94f550e-f058-41e2-bdb6-e5c09e3cbd38", :state (as-other "ready")}]) sql/format))
Execution error (AssertionError) at honeysql.format/seq->sql (format.cljc:385).
Assert failed: Alias should have two parts["ready"]
(= 2 (count x))
user=>
I guess you're using lein
so perhaps you need to do lein clean
and then restart your REPL?
Here's 1.1.610 to show it changed in that release:
seanc@DESKTOP-30ICA76:~/clojure$ clj -Sdeps '{:deps {honeysql/honeysql {:mvn/version "1.0.444"} seancorfield/next.jdbc {:mvn/version "1.1.610"}}}'
Downloading: seancorfield/next.jdbc/1.1.610/next.jdbc-1.1.610.pom from clojars
Downloading: seancorfield/next.jdbc/1.1.610/next.jdbc-1.1.610.jar from clojars
Clojure 1.10.1
user=> (require '[honeysql.core :as sql] '[honeysql.helpers :refer :all] '[next.jdbc.types :refer :all])
WARNING: update already refers to: #'clojure.core/update in namespace: user, being replaced by: #'honeysql.helpers/update
nil
user=> (def s (-> (insert-into :processes) (values [{:id #uuid "b94f550e-f058-41e2-bdb6-e5c09e3cbd38", :state (as-other "ready")}]) sql/format))
#'user/s
user=>
Agree, there’s definitely something odd going on in my project. Maybe the project is borked somehow. I’m looking into it.
@seancorfield lein clean
did the trick.
🙏
Yeah, that can be a problem with lein
, unfortunately. It can, theoretically, happen with the Clojure CLI too but it's rarer in my experience (and easy to "force" a correction with clj -Sforce ...
where it recomputes the dependencies and then re-caches them).
Thanks again. I’m new to Clojure (though plenty of CL in the distant past). Sorry for using up your time on such remedial issues. I really appreciate the help.
No problem at all. That's what we're all here for: to help others in our community!