Skip to content

Extended java.util.HashMap with FHstorable#6

Open
dcj wants to merge 2 commits intoblakesmith:masterfrom
likestream:feature/java-util-map
Open

Extended java.util.HashMap with FHstorable#6
dcj wants to merge 2 commits intoblakesmith:masterfrom
likestream:feature/java-util-map

Conversation

@dcj
Copy link
Copy Markdown

@dcj dcj commented Apr 14, 2013

Hello @blakesmith (and @citizenparker)

Wow, I was so happy to find this library!
I tried to use it, but ran into issues. The writes into the DB worked fine,
but the read path back from Postgres -> JDBC -> Korma -> pghstore didn't work.
Somehow, what was getting passed to from-hstore was a java.util.HashMap, not a
org.postgresql.util.PGobject, so no implementation of from-hstore was found for java.util.HashMap.

Has there been a change with one or more "links in the chain" above?

I am running:
Clojure 1.5.1,
Postgres 9.2.x,
[org.clojure/java.jdbc "0.2.3"]
[postgresql "9.2-1002.jdbc4"]
[korma "0.3.0-RC5"]

Anyway, I didn't take the time to really dig into this to understand what the issue was.
I simply threw together a very quick and dirty implementation of from-hstore for java.util.HashMap, which is here in my pull request, just FYI. I'm not claiming my code is the best or right way to do this, if in fact this needs to be done at all...

I'm pretty sure I am unblocked for now, but it would be great to get some more knowledgeable perspective from you guys on this....

Thanks !

@sparkertime
Copy link
Copy Markdown
Contributor

@dcj Hmm, can you post the code from Korma that was calling from-hstore? That seems very odd. I've used it in environments identical to yours but for the Clojure version with no problem.

@dcj
Copy link
Copy Markdown
Author

dcj commented Apr 14, 2013

@citizenparker

I define my entities like this:

(ns likestream.db.pg.entities
(:use korma.core
pghstore-clj.core))

(defentity businesses
(table :businesses)
(prepare #(update-in % [:details] to-hstore))
(transform #(update-in % [:details] from-hstore))
(prepare #(update-in % [:location] to-hstore))
(transform #(update-in % [:location] from-hstore)))

I then 'use this file/namespace in another file/namespace where I define a number of functions for interacting with
this DB table:

(ns likestream.db.pg.businesses
(:use likestream.db.pg.entities)
(:require [korma.core :as korma]

And here I define functions like "create", "read", and update for my table.

Then in other code, I require this filem

(:require [likestream.db.pg.businesses :as business])

And then call things like

(business/create some-clojure-map)

If this is not enough info to understand why I am having this issue, I can create a small test repo/app
to attempt to reproduce the issue in a small example....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants