Fork me on GitHub
#sql
<
2016-08-02
>
sandbags17:08:00

@mattly: hello from the past, I think I remember you from such IRC channels as #ruby, #ror, or possibly #caboose

mattly17:08:17

possibly all three!

sandbags17:08:42

Am I missing something obvious about getting the id of the last inserted record? I’m using Honeysql `(-> (h/insert-into :people) (h/columns :org-id :given-name :family-name :email) (h/values [[org-id given-name family-name email]]) (sql/format :quoting :mysql :allow-dashed-names? true))` with jdbc/execute! and just back a (1) . I can do a SELECT LAST_INSERT_ID() but I was under the impression I should get back a map of insert keys for a single insert. Have I gone wrong somewhere?

donaldball19:08:36

iirc you want to call db-do-prepared-return-keys and look for :GENERATED_KEY

donaldball19:08:40

it is mildly annoying

sandbags19:08:49

donaldball: i’ll take a look at that, thanks

sandbags19:08:31

i was surprised not to find a lot of queries about this via google, seems a common thing to want

donaldball19:08:59

I reckon most folk just use jdbc/insert! and call it a day

donaldball19:08:20

though I’m a fan of honeysql myself so prefer to use it exclusively when i use it

sandbags20:08:30

how does anyone live without honeysql

sandbags20:08:18

i mean, i’m used to ActiveRecord which - despite its many flaws - makes the common database stuff more or less trivial… the idea of going back to generating raw sql… brrrr

sandbags20:08:32

honeysql seems a pretty good middle ground

donaldball21:08:32

I would rather say that ActiveRecord trivializes interaction with the database, and I mean that in a bad way. A database abstraction that does not require you to think carefully about your transaction boundaries, locking and isolation level requirements is fundamentally unsound.

sandbags22:08:33

i wasn’t singing the praises of AR so much as musing on having to go back to generating raw SQL and wondering why people would forgo something like Honeysql

donaldball23:08:51

I hear that. I think some legitimately don’t need to compose queries at run-time, they can express everything in sql strings. Others I sense have been burned by cumbersome sql object hierarchies or dsls that purport to abstract the difficult bits of sql away but wind up being more trouble than they’re worth (e.g. hibernate’s query language, if that’s even a thing). I find honeysql to be a different beast entirely: it’s essentially just an AST for the most common 90% of sql.