Skip to content
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

execute(...) should be extended with returning generated keys #189

Closed
SzalkaiGabor opened this issue Sep 20, 2019 · 4 comments
Closed

execute(...) should be extended with returning generated keys #189

SzalkaiGabor opened this issue Sep 20, 2019 · 4 comments
Labels
type: enhancement A general enhancement

Comments

@SzalkaiGabor
Copy link

Now it is not possible to create a one-to-one relationship with the execute statement, as if you do like this (see below), the flatMap won't be invoked.

databaseClient.execute("INSERT INTO table_a (something) VALUES (:something)")
                .bind("something", "id")
                .fetch().first()
                .flatMap {
                    databaseClient.execute("INSERT INTO table_b (something, table_a_id) VALUES (:something, :table_a_id)")
                            .bind("something", entry.parameters)
                            .bind("table_a_id", it["id"].toString().toLong())
                            .fetch().rowsUpdated()
                }
                .then()

Possible solutions (@mp911de):

We could either accept a Statement customizer or expose returnGeneratedKeys(…).

@mp911de
Copy link
Member

mp911de commented Sep 20, 2019

This ticket is related to #46 as we want to introduce general customization hooks, similar to WebClient ExchangeFilterFunctions

@mp911de mp911de added the type: enhancement A general enhancement label Sep 20, 2019
@Camsteack
Copy link

Are there any update on that ? As at the moment it's impossible do things like upsert and get the generated id.

@mp911de mp911de added this to the 1.1 M4 (Neumann) milestone Feb 18, 2020
@mp911de
Copy link
Member

mp911de commented Feb 18, 2020

After investigating on this topic, we do not have proper use-cases for the related ticket #46. Therefore, we're going to introduce a slim version of filter functions for Statement objects. The simple (UnaryOperator) code would look like:

DatabaseClient databaseClient = …;
databaseClient.execute("SELECT")
		.filter(s -> s.returnGeneratedValues("foo"))

the bit more extended approach with a StatementFilterFunction would accept also an ExecuteFunction:

DatabaseClient databaseClient = …;
databaseClient.execute("SELECT")
		.filter((s, next) -> next.execute(s.returnGeneratedValues("foo")))

mp911de added a commit that referenced this issue Feb 18, 2020
mp911de added a commit that referenced this issue Feb 18, 2020
We now accept StatementFilterFunction and ExecuteFunction via DatabaseClient to filter Statement execution. StatementFilterFunctions can be used to pre-process the statement or post-process Result objects.

databaseClient.execute(…)
		.filter((s, next) -> next.execute(s.returnGeneratedValues("my_id")))
		.filter((s, next) -> next.execute(s.fetchSize(25)))

databaseClient.execute(…)
		.filter(s -> s.returnGeneratedValues("my_id"))
		.filter(s -> s.fetchSize(25))
mp911de added a commit that referenced this issue Feb 18, 2020
We now accept StatementFilterFunction and ExecuteFunction via DatabaseClient to filter Statement execution. StatementFilterFunctions can be used to pre-process the statement or post-process Result objects.

databaseClient.execute(…)
		.filter((s, next) -> next.execute(s.returnGeneratedValues("my_id")))
		.filter((s, next) -> next.execute(s.fetchSize(25)))

databaseClient.execute(…)
		.filter(s -> s.returnGeneratedValues("my_id"))
		.filter(s -> s.fetchSize(25))
@mp911de mp911de linked a pull request Feb 18, 2020 that will close this issue
schauder pushed a commit that referenced this issue Feb 25, 2020
schauder pushed a commit that referenced this issue Feb 25, 2020
We now accept StatementFilterFunction and ExecuteFunction via DatabaseClient to filter Statement execution. StatementFilterFunctions can be used to pre-process the statement or post-process Result objects.

databaseClient.execute(…)
		.filter((s, next) -> next.execute(s.returnGeneratedValues("my_id")))
		.filter((s, next) -> next.execute(s.fetchSize(25)))

databaseClient.execute(…)
		.filter(s -> s.returnGeneratedValues("my_id"))
		.filter(s -> s.fetchSize(25))
schauder added a commit that referenced this issue Feb 25, 2020
Made assertions in tests more strict.
schauder added a commit that referenced this issue Feb 25, 2020
Refactored DefaultDatabaseClientUnitTests in order to make the relevant differences in setup easier to spot.
mp911de added a commit that referenced this issue Feb 25, 2020
Fix nullability annotations. Relax generics at DatabaseClient.StatementFilterSpec.filter(…).
mp911de added a commit that referenced this issue Mar 16, 2020
mp911de added a commit that referenced this issue Mar 16, 2020
We now accept StatementFilterFunction and ExecuteFunction via DatabaseClient to filter Statement execution. StatementFilterFunctions can be used to pre-process the statement or post-process Result objects.

databaseClient.execute(…)
		.filter((s, next) -> next.execute(s.returnGeneratedValues("my_id")))
		.filter((s, next) -> next.execute(s.fetchSize(25)))

databaseClient.execute(…)
		.filter(s -> s.returnGeneratedValues("my_id"))
		.filter(s -> s.fetchSize(25))
mp911de pushed a commit that referenced this issue Mar 16, 2020
Made assertions in tests more strict.
mp911de pushed a commit that referenced this issue Mar 16, 2020
Refactored DefaultDatabaseClientUnitTests in order to make the relevant differences in setup easier to spot.
mp911de added a commit that referenced this issue Mar 16, 2020
Fix nullability annotations. Relax generics at DatabaseClient.StatementFilterSpec.filter(…).
schauder pushed a commit that referenced this issue Mar 17, 2020
We now accept StatementFilterFunction and ExecuteFunction via DatabaseClient to filter Statement execution. StatementFilterFunctions can be used to pre-process the statement or post-process Result objects.

databaseClient.execute(…)
		.filter((s, next) -> next.execute(s.returnGeneratedValues("my_id")))
		.filter((s, next) -> next.execute(s.fetchSize(25)))

databaseClient.execute(…)
		.filter(s -> s.returnGeneratedValues("my_id"))
		.filter(s -> s.fetchSize(25))

Original pull request: #308.
schauder added a commit that referenced this issue Mar 17, 2020
Made assertions in tests more strict.

Original pull request: #308.
schauder added a commit that referenced this issue Mar 17, 2020
Refactored DefaultDatabaseClientUnitTests in order to make the relevant differences in setup easier to spot.

Original pull request: #308.
schauder pushed a commit that referenced this issue Mar 17, 2020
Fix nullability annotations. Relax generics at DatabaseClient.StatementFilterSpec.filter(…).

Original pull request: #308.
@schauder
Copy link
Contributor

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants