Fork me on GitHub
#sql
<
2019-08-23
>
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"
  [id]
  (let [[query] (sql/query @db-spec
      [ "SELECT IsAdmin From Users
        WHERE UserID=?
        LIMIT 1"
        id])]
    (println
      (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(PgPreparedStatement.java:465)
	at org.postgresql.jdbc.PgPreparedStatement.setObject(PgPreparedStatement.java:948)
	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))]

seancorfield16:08:29

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

seancorfield16:08:01

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

seancorfield16:08:39

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? 😛

seancorfield16:08:24

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

Ashley Smith16:08:03

did you enjoy your time here? 🙂

seancorfield16:08:40

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!

seancorfield16:08:58

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!

gklijs17:08:31

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

seancorfield17:08:11

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

seancorfield17:08:35

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

gklijs19:08:04

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