Skip to content

Commit

Permalink
Add support for JDBI bind list params. (#955 fixes #952)
Browse files Browse the repository at this point in the history
Add support for JDBI bind list params.
  • Loading branch information
nedtwigg authored Oct 2, 2021
2 parents 72e8c21 + 9c0cf78 commit 49b3363
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
* Added `wildcardsLast` option for Java `ImportOrderStep` ([#954](https://github.com/diffplug/spotless/pull/954))

### 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 @@ -5,6 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
## [Unreleased]
* Added `wildcardsLast()` option for Java `importOrder` ([#954](https://github.com/diffplug/spotless/pull/954))

### 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

0 comments on commit 49b3363

Please sign in to comment.