Fork me on GitHub
#honeysql
<
2021-07-26
>
v3ga18:07:15

What would be a good way to go about deleting a record by ID with honeysqł? Newb question, just tinkering around. https://gist.github.com/v3gal0g/0944bae4b784cd96ad53de71c35bb793

seancorfield18:07:15

Hard to tell from that Gist what result you are getting that is different from what you are expecting?

v3ga18:07:41

@seancorfield the jdbc “sql/delete” gives me what I want but thats without honeysql. The other two attempts aren’t doing anything as of yet.

v3ga19:07:00

@seancorfield ok I believe i’ve got it working now.

seancorfield19:07:40

@decim What did you need to change?

v3ga19:07:38

@seancorfield well I thought this would work, Apparently not but that SHOULD be correct…. (-> {:delete-from :books :where [:= :books.id 2]} (honeysql/format))

v3ga19:07:44

I’m looking at your tests now in the library…

seancorfield19:07:43

dev=> (-> {:delete-from :books
 #_=>      :where [:= :books.id 2]}
 #_=>     (sql/format))
["DELETE FROM books WHERE books.id = ?" 2]
What is that db-query-one function you are calling?

v3ga19:07:11

(defn db-query-one [sql] (db/execute-one! data-source sql {:return-keys true :builder-fn rs/as-unqualified-maps}))

v3ga19:07:50

I’m no longer using that, I removed it for the delete. I get the same as what you posted when I evaluate it… oh. That’s one thing I was wondering. My ‘store-book!’ function does store data to the database but the delete isn’t picking up on the data source is my guess.

v3ga19:07:01

@seancorfield ooops, you were giving me a hint there. Now it does in fact work. I was running around like a chicken with his head cut off… =( (-> (hh/delete-from :books) (hh/where := :books.id 2) (honeysql/format) db-query-one)

v3ga19:07:33

I even answered it my damn self without knowing, lol. Thank you.

seancorfield20:07:31

I'm not sure what you even changed 🙂

v3ga21:07:59

@seancorfield it was a round of craziness… I confused myself and executed it without db-query-one, then added it back before making a gist. I’m looking over next.jdbc documentation as well now. I actually learned the very little that i’m using from a tutorial online so I’m tinkering to figure out what all is necessary for the basics.

seancorfield21:07:27

Cool. Feel free to ask Qs here and in #sql whenever you get stuck or need clarification on something in the docs.

v3ga21:07:18

Will do…