Skip to content

Add named parameter support #23

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

Closed
mp911de opened this issue Nov 22, 2018 · 0 comments
Closed

Add named parameter support #23

mp911de opened this issue Nov 22, 2018 · 0 comments
Labels
type: enhancement A general enhancement
Milestone

Comments

@mp911de
Copy link
Member

mp911de commented Nov 22, 2018

We should introduce named parameter support for DatabaseClient and repositories using a uniform naming pattern to decouple from vendor-specific bind marker syntax.

Right now, we need to stick to vendor-specific bind markers if we want to bind parameters to a statement. This makes statements non-portable.

@mp911de mp911de added the type: enhancement A general enhancement label Nov 22, 2018
mp911de added a commit that referenced this issue Jan 4, 2019
mp911de added a commit that referenced this issue Jan 4, 2019
DatabaseClient now supports named parameters prefixed with a colon such as :name in addition to database-native bind markers. Named parameters thus are supported in annotated repository query methods which also increases portability of queries across database vendors.

Named parameter support unrolls collection arguments to reduce the need for argument-specific SQL statements:

db.execute()
    .sql("SELECT id, name, state FROM table WHERE age IN (:ages)")
    .bind("ages", Arrays.asList(35, 50));

Results in a query: SELECT id, name, state FROM table WHERE age IN (35, 50)

Collection arguments containing nested object arrays can be used to use select lists:

List<Object[]> tuples = new ArrayList<>();
tuples.add(new Object[] {"John", 35});
tuples.add(new Object[] {"Ann",  50});

db.execute()
    .sql("SELECT id, name, state FROM table WHERE (name, age) IN (:tuples)")
    .bind("tuples", tuples);

translates to: SELECT id, name, state FROM table WHERE (name, age) IN (('John', 35), ('Ann', 50))
schauder added a commit that referenced this issue Jan 10, 2019
Formatting.
Made Tests simpler and stricter by using `containsExactly`.
Added @test annotation to ignored database specific tests so they actually show up as ignored.
mp911de added a commit that referenced this issue Jan 11, 2019
mp911de added a commit that referenced this issue Jan 11, 2019
DatabaseClient now supports named parameters prefixed with a colon such as :name in addition to database-native bind markers. Named parameters thus are supported in annotated repository query methods which also increases portability of queries across database vendors.

Named parameter support unrolls collection arguments to reduce the need for argument-specific SQL statements:

db.execute()
    .sql("SELECT id, name, state FROM table WHERE age IN (:ages)")
    .bind("ages", Arrays.asList(35, 50));

Results in a query: SELECT id, name, state FROM table WHERE age IN (35, 50)

Collection arguments containing nested object arrays can be used to use select lists:

List<Object[]> tuples = new ArrayList<>();
tuples.add(new Object[] {"John", 35});
tuples.add(new Object[] {"Ann",  50});

db.execute()
    .sql("SELECT id, name, state FROM table WHERE (name, age) IN (:tuples)")
    .bind("tuples", tuples);

translates to: SELECT id, name, state FROM table WHERE (name, age) IN (('John', 35), ('Ann', 50))
mp911de pushed a commit that referenced this issue Jan 11, 2019
Formatting.
Made Tests simpler and stricter by using `containsExactly`.
Added @test annotation to ignored database specific tests so they actually show up as ignored.
mp911de added a commit that referenced this issue Jan 11, 2019
@mp911de mp911de added this to the 1.0 M2 milestone Jan 18, 2019
mp911de added a commit that referenced this issue Jan 18, 2019
DatabaseClient now supports named parameters prefixed with a colon such as :name in addition to database-native bind markers. Named parameters thus are supported in annotated repository query methods which also increases portability of queries across database vendors.

Named parameter support unrolls collection arguments to reduce the need for argument-specific SQL statements:

db.execute()
    .sql("SELECT id, name, state FROM table WHERE age IN (:ages)")
    .bind("ages", Arrays.asList(35, 50));

Results in a query: SELECT id, name, state FROM table WHERE age IN (35, 50)

Collection arguments containing nested object arrays can be used to use select lists:

List<Object[]> tuples = new ArrayList<>();
tuples.add(new Object[] {"John", 35});
tuples.add(new Object[] {"Ann",  50});

db.execute()
    .sql("SELECT id, name, state FROM table WHERE (name, age) IN (:tuples)")
    .bind("tuples", tuples);

translates to: SELECT id, name, state FROM table WHERE (name, age) IN (('John', 35), ('Ann', 50))

Original pull request: #47.
mp911de pushed a commit that referenced this issue Jan 18, 2019
Formatting.
Made Tests simpler and stricter by using `containsExactly`.
Added @test annotation to ignored database specific tests so they actually show up as ignored.

Original pull request: #47.
mp911de added a commit that referenced this issue Jan 18, 2019
Original pull request: #47.
@mp911de mp911de closed this as completed Jan 18, 2019
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

No branches or pull requests

1 participant