Skip to content

Commit 2d75ed8

Browse files
committed
🐛 Fixed java.lang.ClassCastException: class com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement cannot be cast to class com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement #32
1 parent 55d69d5 commit 2d75ed8

File tree

1 file changed

+11
-11
lines changed
  • src/main/java/com/github/maiqingqiang/goormhelper/sql2struct/impl

1 file changed

+11
-11
lines changed

src/main/java/com/github/maiqingqiang/goormhelper/sql2struct/impl/SQL2Struct.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,23 @@ public String convert() {
8787
}
8888

8989
private void singleConvert(@NotNull StringBuilder stringBuilder, SQLStatement statement) {
90-
SQLCreateTableStatement createTableStatement = (SQLCreateTableStatement) statement;
90+
if (statement instanceof SQLCreateTableStatement createTableStatement) {
91+
String tableName = Strings.clearQuote(createTableStatement.getTableName());
92+
tableName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, tableName);
9193

92-
String tableName = Strings.clearQuote(createTableStatement.getTableName());
93-
tableName = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, tableName);
94+
stringBuilder.append("type ").append(tableName).append(" struct {\n");
9495

95-
stringBuilder.append("type ").append(tableName).append(" struct {\n");
9696

97+
List<SQLTableElement> tableElementList = createTableStatement.getTableElementList();
9798

98-
List<SQLTableElement> tableElementList = createTableStatement.getTableElementList();
99-
100-
for (SQLTableElement sqlTableElement : tableElementList) {
101-
if (sqlTableElement instanceof SQLColumnDefinition sqlColumnDefinition) {
102-
generateStructField(stringBuilder, sqlColumnDefinition);
99+
for (SQLTableElement sqlTableElement : tableElementList) {
100+
if (sqlTableElement instanceof SQLColumnDefinition sqlColumnDefinition) {
101+
generateStructField(stringBuilder, sqlColumnDefinition);
102+
}
103103
}
104-
}
105104

106-
stringBuilder.append("}\n\n");
105+
stringBuilder.append("}\n\n");
106+
}
107107
}
108108

109109
protected String getGoType(@NotNull SQLColumnDefinition definition) {

0 commit comments

Comments
 (0)