-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6031 from cktk/3.0
✨ 支持SQLite的DDL自动维护功能 优化getDdlGenerator的方法 之前的写法会把SQLite当做pgsql进行处理
- Loading branch information
Showing
2 changed files
with
77 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...sion/src/main/java/com/baomidou/mybatisplus/extension/ddl/history/SQLiteDdlGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.baomidou.mybatisplus.extension.ddl.history; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.function.Function; | ||
|
||
|
||
@Component | ||
public class SQLiteDdlGenerator implements IDdlGenerator { | ||
|
||
public static IDdlGenerator newInstance() { | ||
return new SQLiteDdlGenerator(); | ||
} | ||
|
||
@Override | ||
public boolean existTable(String databaseName, Function<String, Boolean> executeFunction) { | ||
StringBuffer sql = new StringBuffer(); | ||
sql.append("SELECT count(1) FROM sqlite_master WHERE name='"); | ||
sql.append(getDdlHistory()).append("' AND type='table'"); | ||
return executeFunction.apply(sql.toString()); | ||
} | ||
|
||
@Override | ||
public String createDdlHistory() { | ||
StringBuffer sql = new StringBuffer(); | ||
sql.append("CREATE TABLE IF NOT EXISTS `").append(getDdlHistory()).append("` ("); | ||
sql.append("script TEXT primary key,"); | ||
sql.append("type TEXT,"); | ||
sql.append("version TEXT"); | ||
sql.append(");"); | ||
return sql.toString(); | ||
} | ||
} |