Insert db strings with Korma

I have a DB table that uses the following schema:

CREATE TABLE users (id SERIAL PRIMARY KEY, username TEXT UNIQUE NOT NULL, password TEXT NOT NULL, email TEXT NOT NULL, admin BOOLEAN NOT NULL, active BOOLEAN NOT NULL, created DATE NOT NULL); 

I use Korma, defining a users object

 (defentity users (has-many tips)) 

And I'm trying to minify values ​​using the following functions:

 (defn make-user-vals [username pass email] "Creates an active, non-admin user" {:username username, :password (crypt/encrypt pass), :email email, :admin false, :active true, :created (java.util.Date.)}) (defn seed-users! [] (insert ent/users (values (users/make-user-vals "admin" "f00b4r" " foo@example.com ")))) 

(seed-users!) crashes with a message (not very informative for my eyes):

 Failure to execute query with SQL: INSERT INTO users (username, password, email, admin, active, created) VALUES (?, ?, ?, FALSE, TRUE, ?) :: [admin $2a$10$AVdxz9HvYOyszhcXVrTVi.oBcbz9EZVfGZYNUI3iDMb0hj3igvpEy foo@example.com #<Date Wed Feb 15 21:59:10 CET 2012>] ClassCastException java.lang.RuntimeException cannot be cast to java.sql.SQLException clojure.java.jdbc/print-sql-exception (jdbc.clj:350) 

Any idea why?

(if this helps, the database query works, so it doesn't look like a connection problem)

Thanks!

+4
source share
1 answer

You need to use java.sql.Date , not java.util.Date :

 (java.sql.Date. 2012 2 16) 

By the way, you can learn clj-time as a clj-time handling solution. The standard Java classes associated with time and date are completely insane (as evidenced by this release).

+6
source

Source: https://habr.com/ru/post/1396723/


All Articles