Korma - cannot acquire connections

434 views
Skip to first unread message

AndyK

unread,
Nov 4, 2011, 11:44:59 AM11/4/11
to Clojure
I believe I have setup korma correctly with
(require '[korma.db :as db])
(require '[korma.core :as sql])
(db/defdb devdb (db/mysql {:db "mydb" :host "localhost" :user
"me" :password "mypass"}))
(sql/defentity mytable
(sql/select mytable (sql/fields :id) (sql/where {:id 1})))

But I'm getting
SQLException:
Message: Connections could not be acquired from the underlying
database!
SQLState: null
Error Code: 0

(db/get-connection devdb) returns a clojure.lang.PersistentHashMap -
is that right? or should it be the underlying java.sql.Connection?

I have the mysql driver in my classpath, am able to Class/forName the
driver, create a connection, and query on the connection - all
manually. Korma looks pretty cool and I'd like to be using, any ideas?

Base

unread,
Nov 4, 2011, 4:21:59 PM11/4/11
to Clojure
Did you mean to define the select within the defentity?

(sql/defentity mytable  (sql/select mytable (sql/fields :id) (sql/
where {:id 1})))

I does this work?

(sql/defentity mytable
(:pk <<< YOUR PRIMARY KEY AS A KEYWORD>>>)
(table <<<YOUR TABLE NAME AS A KEYWORD>>>)
(database devdb))

(sql/select mytable (sql/fields :id) (sql/where {:id 1}))

Base

unread,
Nov 4, 2011, 4:24:27 PM11/4/11
to Clojure
Actually it should read:

(sql/defentity mytable
(:pk <<< YOUR PRIMARY KEY AS A KEYWORD>>>)
(sql/table <<<YOUR TABLE NAME AS A KEYWORD>>>)
(sql/database devdb))

(sql/select mytable (sql/fields :id) (sql/where {:id 1}))



AndyK

unread,
Nov 6, 2011, 12:57:41 PM11/6/11
to Clojure
My mistake in the original post - that should've read (sql/defenity
mytable)
Two seprate forms - the defentity + the select.

On Nov 4, 3:21 pm, Base <basselh...@gmail.com> wrote:
> Did you mean to define the select within the defentity?
>
> (sql/defentity mytable    (sql/select mytable (sql/fields :id) (sql/
> where {:id 1})))
>
> I does this work?
>
> (sql/defentity mytable
>   (:pk <<< YOUR PRIMARY KEY AS A KEYWORD>>>)
>   (table <<<YOUR TABLE NAME AS A KEYWORD>>>)
>  (database devdb))
>
> (sql/select mytable (sql/fields :id) (sql/where {:id 1}))
>

David Cabana

unread,
Nov 6, 2011, 7:42:46 PM11/6/11
to clo...@googlegroups.com
This worked for me, with mysql 5.1 on Ubuntu Natty. The clojure_test
library and fruit table already existed.

(ns foo.core
(use [korma.db])
(use [korma.core]))

(defdb mydb {:subprotocol "mysql"
:subname "//127.0.0.1:3306/clojure_test"
:user "clojure_test"
:password "clojure_test"})

(defentity fruit
(database mydb)
(table :fruit))

(select fruit)

Reply all
Reply to author
Forward
0 new messages