Fork me on GitHub
#sql
<
2019-05-12
>
emccue00:05:33

another smallish question

emccue00:05:49

how do i get the id of something I just inserted?

emccue00:05:57

I am using sqlite with hugsql

emccue00:05:10

insert queries seem to just return (1)

emccue00:05:50

(insert-developer! db {:email ""})
=> {:last_insert_rowid() 4}

emccue00:05:02

-- :name insert-developer!
-- :command :insert
INSERT INTO DEVELOPERS (email)
VALUES (:email);

emccue00:05:12

...i technically have the info

emccue00:05:34

but :last_insert_rowid() is a ...obnoxious keyword

seancorfield06:05:12

@emccue The "last inserted ID" is different in pretty much every database. In MySQL it's :GENERATED_KEY for example. PostgreSQL tends to return the entire row including the newly inserted key.

seancorfield06:05:50

The various JDBC drivers often can't even be guaranteed to return keys rather than just update counts.

seancorfield06:05:09

As the maintainer of clojure.java.jdbc, this sort of crazy variability drives me crazy...

emccue07:05:33

ah so its sqlite wierdness

kulminaator07:05:01

in postgresql you can actually define what you want to be returned 🙂

kulminaator07:05:15

(it's just giving you more possible choices to make mistakes)

emccue07:05:41

for now im just making a small internal app, so sqlite will work fine

emccue07:05:33

i think i should get a grip on that before doing a deeper dive into the more powerful sql databases

orestis09:05:07

Note that SQLite has its own idiosyncrasies that can bite you. Though the fact that you don’t have to deal with user management is nice.

nha11:05:07

Anyone has encountered something like that before?

java.lang.IllegalAccessException: Class clojure.core$bean$fn__6906$fn__6907 can not access a member of class com.facebook.presto.jdbc.internal.client.FailureInfo$FailureException with modifiers "public"
It happens with presto - doesn’t seem to be related to java.jdbc, but I guess you would encounter that when converting data from a DB

emccue14:05:33

thats...potentially ugly

emccue14:05:51

id say open a bug with facebook

emccue14:05:19

and then maybe use reflection to make litterally everything about that class public so you can move on

ikitommi19:05:46

the results of the TechEmpower single-query benchmark just finished with porsas (part of the reitit suite) entry. Here’s the list of Clojure Entries:

ikitommi19:05:14

It’s already good, but I think there is room of improvement, might be just server & pool config. Fastest Java-version on Undertow is 410k.

ikitommi19:05:41

But, I think I’ll move to support async-db-stuff with porsas, to see how that matters. Starting with PostgreSQL.

ikitommi19:05:12

my 2 cents for being able to get within 5% of the fastest java setups with Clojure. Which would be kinda awesome.