LispCast Web Development in Clojure - part 2 - JDBC/Postgres Error


#1

Hey guys, I’m having problems to follow the tutorial.

I’m trying to do the inserts like on the video (19:30), but I got this error message:

org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of clojure.lang.PersistentVector. Use setObject() with an explicit Types value to specify the type to use.

The method:

(defn create-item [db name description]
  (:id (first (db/query
                db
                ["INSERT INTO items (name, description) VALUES (?, ?) RETURNING id"
                 name
                 description]))))

The handler:

(defn handle-create-item [req]
  (let [name [get-in req [:params "name"]]
        description [get-in req [:params "description"]]
        db (:webdev/db req)
        item-id (create-item db name description)]
    {:status 302
     :headers {"Location" "/items"}
     :body ""}))

The project.clj

(defproject webdev "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [ring "1.6.3"]
                 [compojure "1.6.0"]
                 [org.clojure/java.jdbc "0.7.5"]
                 [org.postgresql/postgresql "42.1.4"]]
  :main webdev.core
  :min-lein-version "2.8.0"
  :uberjar-name "webdev.jar"
  :profiles {:dev
             {:main webdev.core/-dev-main}})

Could you help me with this?

Thanks :slight_smile:


#2

Sorry, I found the error.

In the handler, on params I call [get-in req ...] instead of (get-in req ...). :confused:

Thanks