-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DbClient - can we return generated id(s)? #2279
Comments
Good question. We have no statement that keeps execution info in it. Everything is in returned Future. In case of DML it's just number of modified records. Maybe we can extend this future value to contain a bit more. |
Currently, I have to handle it myself. public Single<UUID> save(Post post) {
return this.dbClient
.execute(exec -> exec
.query("INSERT INTO posts(title, content) VALUES (?, ?) RETURNING id", post.getTitle(), post.getContent())
)
.first()
.map(data -> data.column("id").as(UUID.class));
} |
Investigating - for now I am trying to add a new method to the API that would return the generated ids, so I do not break backward compatibility. |
This seems like a very useful addition to the API |
I have some time to have a look at this now. But I'll do it as part of 4.x where DB Client is synchronnous. |
@tomas-langer We have to extend DbStatementDml inerface methods. Currently we have single prototype there:
Which returns value of
2nd:
|
Signed-off-by: Tomáš Kraus <[email protected]>
Signed-off-by: Tomáš Kraus <[email protected]>
Signed-off-by: Tomáš Kraus <[email protected]>
Signed-off-by: Tomáš Kraus <[email protected]>
Signed-off-by: Tomáš Kraus <[email protected]>
Signed-off-by: Tomáš Kraus <[email protected]>
Signed-off-by: Tomáš Kraus <[email protected]>
Signed-off-by: Tomáš Kraus <[email protected]>
Signed-off-by: Tomáš Kraus <[email protected]>
Environment Details
Problem Description
When using autogenerated ids (or sequences), we need to return the id used from the insert statement. This is currently not possible with db client.
In JDBC, this is possible using
Statement.RETURN_GENERATED_KEYS
and
Statement::getGeneratedKeys
see https://stackoverflow.com/questions/9353167/auto-increment-id-in-h2-database
The text was updated successfully, but these errors were encountered: