Fork me on GitHub
Ashley Smith16:08:23

Hey everyone -I'm trying to simply retrieve a bool out of my database like so:

(defn- check-privilages
  "Checks if the userID is an admin"
  (let [[query] (sql/query @db-spec
      [ "SELECT IsAdmin From Users
        WHERE UserID=?
        LIMIT 1"
      (true? (:users/isadmin query)))
    (assoc id :is-admin 
      (true? (:users/isadmin query)))))
However, both the println and the assoc statements cause this error, which I haven't run into before after extensive use of my database:
org.postgresql.util.PSQLException: No hstore extension installed.
	at org.postgresql.jdbc.PgPreparedStatement.setMap(
	at org.postgresql.jdbc.PgPreparedStatement.setObject(
	at next.jdbc.prepare$eval5154$fn__5155.invokePrim(prepare.clj:36)
	at next.jdbc.prepare$eval5154$fn__5155.invoke(prepare.clj)

Ashley Smith16:08:53

I'm calling it like so :

id (check-privilages (:identity request))]


You're treating id as a hash map (the assoc). Is it numeric or a hash map? If it is a hash map, then you'll need to extract just the ID value in the sql/query call where id is a parameter @ashley


The call to .setMap in the stacktrace suggests id is a hash map...

Ashley Smith16:08:34

oh my gosh you're right, I forgot to destructure it. Been doing some heavy refactoring! Let me try again


Also, BTW, if could replace (let [[query] (sql/query ,,,)] ,,,) with (let [query (jdbc/execute-one! ,,,)] ,,,) (and I'd probably use result or row instead of query.

Ashley Smith16:08:44

It is, its the identity of request to my server. I used to pass in the ID, but now I'm passing in the entire identity map, so that this function can elevate privileges for the current API call

Ashley Smith16:08:58

always helps to have fresh eyes when you've been working with the same code for hours

Ashley Smith16:08:41

yeah, I've been using the sql-friendly functions like insert! rather than execute-one!. Is query not a good convention then?

Ashley Smith16:08:21

@seancorfield are you still on vacation? What ar eyou doing on here? 😛


Got back from the UK Tuesday. Working, working, working now 🙂

Ashley Smith16:08:03

did you enjoy your time here? 🙂


It was great. Got to see mum for a day at each end and the cat show in Stoke-on-Trent was a lot of fun!


Driving around the M25 in the torrential rain during rush hour, not so much 🙂

Ashley Smith16:08:29

it happens 😛 i'm glad you had fun though!


Any specific breed of cats? We have 8 Norwegian Forrest cats living here 🙂.


@U26FJ5FDM The cat show is "all breed" so it's up to 70 different breeds, as well as "household pet" which is mixed breed.


There were probably 30 different breeds at this show (and about 100 cats total).


I never went to a show, my girlfriend did, and planned several times to go with one of our cats, but didn't work out so far.

🐱 4