Skip to content

Commit 49b3363

Browse files
authored
Add support for JDBI bind list params. (#955 fixes #952)
Add support for JDBI bind list params.
2 parents 72e8c21 + 9c0cf78 commit 49b3363

File tree

9 files changed

+30
-4
lines changed

9 files changed

+30
-4
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1212
## [Unreleased]
1313
* Added `wildcardsLast` option for Java `ImportOrderStep` ([#954](https://github.com/diffplug/spotless/pull/954))
1414

15+
### Added
16+
* Added support for JBDI bind list params in sql formatter ([#955](https://github.com/diffplug/spotless/pull/955))
17+
1518
## [2.18.0] - 2021-09-30
1619
### Added
1720
* Added support for custom JSR223 formatters ([#945](https://github.com/diffplug/spotless/pull/945))

lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLTokenizedFormatter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ private List<FormatterToken> format(final List<FormatterToken> argList) {
138138
argList.remove(index + 1);
139139
argList.remove(index + 1);
140140
}
141+
142+
// JDBI bind list
143+
if (tokenString.equals("<") && t1.getType() == TokenType.NAME && token2String.equals(">")) {
144+
t0.setString(t0.getString() + t1.getString() + t2.getString());
145+
argList.remove(index + 1);
146+
argList.remove(index + 1);
147+
}
141148
}
142149

143150
int indent = 0;

plugin-gradle/CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
55
## [Unreleased]
66
* Added `wildcardsLast()` option for Java `importOrder` ([#954](https://github.com/diffplug/spotless/pull/954))
77

8+
### Added
9+
* Added support for JBDI bind list params in sql formatter ([#955](https://github.com/diffplug/spotless/pull/955))
10+
811
## [5.15.2] - 2021-09-27
912
### Changed
1013
* 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+.

plugin-maven/CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66

7+
### Added
8+
* Added support for JBDI bind list params in sql formatter ([#955](https://github.com/diffplug/spotless/pull/955))
9+
710
## [2.15.0] - 2021-09-30
811
### Added
912
* Added support for custom JSR223 formatters ([#945](https://github.com/diffplug/spotless/pull/945))

testlib/src/main/resources/sql/dbeaver/full.clean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ WHERE
5151
table3.name = 'Foo Bar'
5252
AND table3.type = 'unknown_type'
5353
AND table3.param =:aParam
54+
AND table3.listParam IN(<listParam>)
5455
)
5556
GROUP BY
5657
table1.id,
5758
table2.number
5859
ORDER BY
59-
table1.id;
60+
table1.id;

testlib/src/main/resources/sql/dbeaver/full.dirty

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ DELETE FROM TABLE1 WHERE a=1;
99
UPDATE TABLE1 SET a=2 WHERE a=1;
1010

1111
SELECT table1.id, table2.number, SUM(table1.amount) FROM table1 INNER JOIN table2 ON table.id = table2.table1_id
12-
WHERE table1.id IN (SELECT table1_id FROM table3 WHERE table3.name = 'Foo Bar' and table3.type = 'unknown_type' And table3.param = :aParam)
13-
GROUP BY table1.id, table2.number ORDER BY table1.id;
12+
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 > ))
13+
GROUP BY table1.id, table2.number ORDER BY table1.id;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SELECT
2+
*
3+
FROM
4+
TABLE
5+
WHERE
6+
id IN(<ids>)
7+
AND user_id =:user_id;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT * FROM table WHERE id IN (<ids>) AND user_id = :user_id;

testlib/src/test/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStepTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ void behavior() throws Exception {
3535
.testResource("sql/dbeaver/full.dirty", "sql/dbeaver/full.clean")
3636
.testResource("sql/dbeaver/V1_initial.sql.dirty", "sql/dbeaver/V1_initial.sql.clean")
3737
.testResource("sql/dbeaver/alter-table.dirty", "sql/dbeaver/alter-table.clean")
38-
.testResource("sql/dbeaver/create.dirty", "sql/dbeaver/create.clean");
38+
.testResource("sql/dbeaver/create.dirty", "sql/dbeaver/create.clean")
39+
.testResource("sql/dbeaver/jdbi-params.dirty", "sql/dbeaver/jdbi-params.clean");
3940
}
4041

4142
@Test

0 commit comments

Comments
 (0)