Fork me on GitHub
#honeysql
<
2022-04-11
>
dev-hartmann16:04:50

I have an issue with a query of mine returning a org.postgresql.util.PGobject

dev-hartmann16:04:07

i have a one to many relation

dev-hartmann16:04:23

customer <- order

dev-hartmann16:04:33

my honeysql query looks like this

dev-hartmann16:04:48

(-> (hh/select-distinct :customer :order)
    (hh/from :customer)
    (hh/left-join [:order] [:= :customer.id :order.customer_id])
    (hh/where [:= :customer.id :?id])
    (sql/format {:params {:id id}}))

dev-hartmann16:04:58

the resulting sql query:

dev-hartmann16:04:53

"SELECT DISTINCT customer, order FROM customer LEFT JOIN order ON customer.id = order.customer_id WHERE customer.id = ?"

dev-hartmann16:04:49

this being the result when evaluated in the REPL

dev-hartmann16:04:53

[{:customer #object[org.postgresql.util.PGobject 0x15feceb3 "(1,\"test customer\",\"jerry)"],
  :order #object[org.postgresql.util.PGobject 0x680eec30 "(1,1,\"test order 1\")"]}
 {:customer #object[org.postgresql.util.PGobject 0x701081a7 "(1,\"test customer\",\"jerry)"],
  :order #object[org.postgresql.util.PGobject 0x13f2d1a6 "(2,1,\"test order 2\")"]}
 {:customer #object[org.postgresql.util.PGobject 0x65c70b0b "(1,\"test customer\",\"jerry)"],
  :order #object[org.postgresql.util.PGobject 0x51f2659f "(4,1,\"test order 4\)"]}]

dev-hartmann16:04:20

what I obiously want to do is create a map from that like {:id 1 :desc "test customer" :name "jerry :tasks [{....} {....]}

dev-hartmann16:04:27

but I have no clue how to do that

dev-hartmann16:04:33

anyone able to help?

dev-hartmann16:04:23

especially how to deal with the pgobject

dev-hartmann18:04:08

Nevermind folks, found the answer with changing my query‘ select section