Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Extended java.util.HashMap with FHstorable #6

Open
wants to merge 2 commits into from

2 participants

@dcj

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 !

@citizenparker

@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

@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....

Donald Clark Jackson Can't remember :-( 71cf9ee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 14, 2013
  1. Extended java.util.HashMap with FHstorable

    Donald Clark Jackson authored
Commits on Jun 23, 2013
  1. Can't remember :-(

    Donald Clark Jackson authored
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 5 deletions.
  1. +4 −3 project.clj
  2. +12 −2 src/pghstore_clj/core.clj
View
7 project.clj
@@ -1,7 +1,8 @@
-(defproject pghstore-clj "0.1.0"
+(defproject net.likestream/pghstore-clj "0.1.2"
:description "Helper functions for working with PostgresSQL hstore data type in Clojure via JDBC"
:url "http://github.com/blakesmith/pghstore-clj"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
- :dependencies [[org.clojure/clojure "1.4.0"]]
- :dev-dependencies [[postgresql "9.1-901.jdbc4"]])
+ :dependencies [[org.clojure/clojure "1.5.1"]
+ [prismatic/plumbing "0.0.1"]]
+ :dev-dependencies [[postgresql "9.2-1002.jdbc4"]])
View
14 src/pghstore_clj/core.clj
@@ -1,5 +1,6 @@
(ns pghstore-clj.core
- (:require [clojure.string :as st])
+ (:require [clojure.string :as st]
+ [plumbing.core :refer :all])
(:import [org.postgresql.util PGobject]))
(defprotocol THstorable
@@ -28,4 +29,13 @@
(map (fn [v]
(map #(st/replace % #"\"" "") (st/split v #"=>")))
(st/split (.getValue this) #", "))]
- [(keyword k) v])))))
+ [(keyword k) v])))))
+
+(extend-type java.util.HashMap
+ FHstorable
+ (from-hstore
+ [this]
+ (->> this
+ (into {})
+ keywordize-map)))
+
Something went wrong with that request. Please try again.