korma / Korma

Tasty SQL for Clojure.
http://sqlkorma.com
1.47k stars 222 forks source link

enable to specify extra queries of JDBC URL #290

Closed federkasten closed 9 years ago

federkasten commented 9 years ago

Improved #259 and #227.

I added the :extra option into korma.db/connection-pool and a test case for handling non-ascii characters.

Extra queries are useful for passing properties to JDBC.

In particular, to make MySQL support non-ascii characters, I have to append queries (e.g. ?useUnicode=true&characterEncoding=utf8) to JDBC URL.

I tested this PR on MySQL(MariaDB) and PostgreSQL. I couldn't test on other databases,

Thanks.

immoh commented 9 years ago

Looks good. My only concern is the keyword name, wouldn't properties or parameters be more descriptive than extras?

federkasten commented 9 years ago

It makes sense. I have substituted extra with properties. Thanks.

immoh commented 9 years ago

Excellent. Can you squash everything into a single commit? Thanks.

federkasten commented 9 years ago

Sure. Done.

immoh commented 9 years ago

I needed to make some changes to this.

I found out that you can already set driver properties if Korma is not using connection pool by simply adding key value pairs to to the spec map. For example:

(mysql {:db "korma" :user "root" :useUnicode true :characterEncoding "utf8"})

I changed the solution so that the properties can be given as additional keys in the spec map and the keys can be keywords as well. Internally it doesn't append them to the JDBC url but uses the the .setProperties method of the datasource instead. This is in line with implementation in clojure.java.jdbc which uses java Properties as well.

federkasten commented 9 years ago

:ok_hand: