com-lihaoyi / scalasql

Scala ORM to query SQL databases from Scala via concise, type-safe, and familiar case classes and collection operations. Connects to Postgres, MySql, H2, and Sqlite out of the box
194 stars 22 forks source link

Using the H2Dialect, how does one retrieve auto-generated keys? #8

Closed lihaoyi closed 7 months ago

lihaoyi commented 7 months ago

Discussed in https://github.com/com-lihaoyi/scalasql/discussions/7

Originally posted by **aboisvert** April 10, 2024 The H2Dialect doesn't support the 'returning' clause, so I'm wondering what's the recommended way to retrieve auto-generated keys? (e.g. upon insert, it's typical to retrieve a row's generated primary key such as `id`) This is typically done at a low-level through `JdbcStatement.getGeneratedKeys` but I don't see this capability available through the scalasql abstractions. https://h2database.com/javadoc/org/h2/jdbc/JdbcStatement.html#getGeneratedKeys--
lihaoyi commented 7 months ago

@aboisvert I cut a 0.1.2 which supports .getGeneratedKeys[Int] on insert clauses, can you try it out

aboisvert commented 7 months ago

Awesome, thank you!! I will try it out this week and report back any issues (if any).