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

Add support for JDBI bind list params. #955

Merged
merged 3 commits into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]

### Added
* Added support for JBDI bind list params in sql formatter ([#955](https://github.com/diffplug/spotless/pull/955))

## [2.18.0] - 2021-09-30
### Added
* Added support for custom JSR223 formatters ([#945](https://github.com/diffplug/spotless/pull/945))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ private List<FormatterToken> format(final List<FormatterToken> argList) {
argList.remove(index + 1);
argList.remove(index + 1);
}

// JDBI bind list
if (tokenString.equals("<") && t1.getType() == TokenType.NAME && token2String.equals(">")) {
t0.setString(t0.getString() + t1.getString() + t2.getString());
argList.remove(index + 1);
argList.remove(index + 1);
}
}

int indent = 0;
Expand Down
3 changes: 3 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]

### Added
* Added support for JBDI bind list params in sql formatter ([#955](https://github.com/diffplug/spotless/pull/955))

## [5.15.2] - 2021-09-27
### Changed
* Added support and bump Eclipse formatter default versions to `4.21` for `eclipse-cdt`, `eclipse-jdt`, `eclipse-wtp`. Change is only applied for JVM 11+.
Expand Down
3 changes: 3 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]

### Added
* Added support for JBDI bind list params in sql formatter ([#955](https://github.com/diffplug/spotless/pull/955))

## [2.15.0] - 2021-09-30
### Added
* Added support for custom JSR223 formatters ([#945](https://github.com/diffplug/spotless/pull/945))
Expand Down
3 changes: 2 additions & 1 deletion testlib/src/main/resources/sql/dbeaver/full.clean
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ WHERE
table3.name = 'Foo Bar'
AND table3.type = 'unknown_type'
AND table3.param =:aParam
AND table3.listParam IN(<listParam>)
)
GROUP BY
table1.id,
table2.number
ORDER BY
table1.id;
table1.id;
4 changes: 2 additions & 2 deletions testlib/src/main/resources/sql/dbeaver/full.dirty
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ DELETE FROM TABLE1 WHERE a=1;
UPDATE TABLE1 SET a=2 WHERE a=1;

SELECT table1.id, table2.number, SUM(table1.amount) FROM table1 INNER JOIN table2 ON table.id = table2.table1_id
WHERE table1.id IN (SELECT table1_id FROM table3 WHERE table3.name = 'Foo Bar' and table3.type = 'unknown_type' And table3.param = :aParam)
GROUP BY table1.id, table2.number ORDER BY table1.id;
WHERE table1.id IN (SELECT table1_id FROM table3 WHERE table3.name = 'Foo Bar' and table3.type = 'unknown_type' And table3.param = :aParam aNd table3.listParam IN ( <listParam > ))
GROUP BY table1.id, table2.number ORDER BY table1.id;
7 changes: 7 additions & 0 deletions testlib/src/main/resources/sql/dbeaver/jdbi-params.clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT
*
FROM
TABLE
WHERE
id IN(<ids>)
AND user_id =:user_id;
1 change: 1 addition & 0 deletions testlib/src/main/resources/sql/dbeaver/jdbi-params.dirty
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM table WHERE id IN (<ids>) AND user_id = :user_id;
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ void behavior() throws Exception {
.testResource("sql/dbeaver/full.dirty", "sql/dbeaver/full.clean")
.testResource("sql/dbeaver/V1_initial.sql.dirty", "sql/dbeaver/V1_initial.sql.clean")
.testResource("sql/dbeaver/alter-table.dirty", "sql/dbeaver/alter-table.clean")
.testResource("sql/dbeaver/create.dirty", "sql/dbeaver/create.clean");
.testResource("sql/dbeaver/create.dirty", "sql/dbeaver/create.clean")
.testResource("sql/dbeaver/jdbi-params.dirty", "sql/dbeaver/jdbi-params.clean");
}

@Test
Expand Down