screw數(shù)據(jù)庫(kù)表結(jié)構(gòu)文檔生成工具
在企業(yè)級(jí)開發(fā)中、我們經(jīng)常會(huì)有編寫數(shù)據(jù)庫(kù)表結(jié)構(gòu)文檔的時(shí)間付出,從業(yè)以來,待過幾家企業(yè),關(guān)于數(shù)據(jù)庫(kù)表結(jié)構(gòu)文檔狀態(tài):要么沒有、要么有、但都是手寫、后期運(yùn)維開發(fā),需要手動(dòng)進(jìn)行維護(hù)到文檔中,很是繁瑣、如果忘記一次維護(hù)、就會(huì)給以后工作造成很多困擾、無形中制造了很多坑留給自己和后人,于是萌生了要自己寫一個(gè)插件工具的想法,但由于自己前期在程序設(shè)計(jì)上沒有很多造詣,且能力偏低,有想法并不能很好實(shí)現(xiàn),隨著工作閱歷的增加,和知識(shí)的不斷儲(chǔ)備,終于在2020年的3月中旬開始進(jìn)行編寫,4月上旬完成初版,想完善差不多在開源,但由于工作太忙,業(yè)余時(shí)間不足,沒有在進(jìn)行完善,到了6月份由于工作原因、頻繁設(shè)計(jì)和更改數(shù)據(jù)庫(kù)、經(jīng)常使用自己寫的此插件、節(jié)省了很多時(shí)間,解決了很多問題 ,在僅有且不多的業(yè)余時(shí)間中、進(jìn)行開源準(zhǔn)備,于2020年6月22日,開源,歡迎大家使用、建議、并貢獻(xiàn)。
關(guān)于名字,想一個(gè)太難了,好在我這個(gè)聰明的小腦瓜靈感一現(xiàn),怎么突出它的小,但重要呢?從小就學(xué)過雷鋒的螺絲釘精神,摘自雷鋒日記:雖然是細(xì)小的螺絲釘,是個(gè)細(xì)微的小齒輪,然而如果缺了它,那整個(gè)的機(jī)器就無法運(yùn)轉(zhuǎn)了,慢說是缺了它,即使是一枚小螺絲釘沒擰緊,一個(gè)小齒輪略有破損,也要使機(jī)器的運(yùn)轉(zhuǎn)發(fā)生故障的...,感覺自己寫的這個(gè)工具,很有這意味,雖然很小、但是開發(fā)中缺了它還不行,于是便起名為 screw(螺絲釘)。
特點(diǎn)
- 簡(jiǎn)潔、輕量、設(shè)計(jì)良好
- 多數(shù)據(jù)庫(kù)支持
- 多種格式文檔
- 靈活擴(kuò)展
- 支持自定義模板
數(shù)據(jù)庫(kù)支持
-
MySQL
-
MariaDB
-
TIDB
-
Oracle
-
SqlServer
-
PostgreSQL
-
Phoenix HBase
-
CacheDB
-
H2
-
DB2
-
HSQL
-
SQLLte
-
瀚高
-
達(dá)夢(mèng)
-
虛谷
-
人大金倉(cāng)
文檔生成支持
-
html
-
word
-
markdown
使用方式
普通方式
-
引入依賴
<dependency> <groupId>cn.smallbun.screw</groupId> <artifactId>screw-core</artifactId> <version>${lastVersion}</version> </dependency> -
編寫代碼
/**
* 文檔生成
*/
void documentGeneration() {
//數(shù)據(jù)源
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/database");
hikariConfig.setUsername("root");
hikariConfig.setPassword("password");
//設(shè)置可以獲取tables remarks信息
hikariConfig.addDataSourceProperty("useInformationSchema", "true");
hikariConfig.setMinimumIdle(2);
hikariConfig.setMaximumPoolSize(5);
DataSource dataSource = new HikariDataSource(hikariConfig);
//生成配置
EngineConfig engineConfig = EngineConfig.builder()
//生成文件路徑
.fileOutputDir(fileOutputDir)
//打開目錄
.openOutputDir(true)
//文件類型
.fileType(EngineFileType.HTML)
//生成模板實(shí)現(xiàn)
.produceType(EngineTemplateType.freemarker).build();
//忽略表
ArrayList<String> ignoreTableName = new ArrayList<>();
ignoreTableName.add("test_user");
ignoreTableName.add("test_group");
//忽略表前綴
ArrayList<String> ignorePrefix = new ArrayList<>();
ignorePrefix.add("test_");
//忽略表后綴
ArrayList<String> ignoreSuffix = new ArrayList<>();
ignoreSuffix.add("_test");
ProcessConfig processConfig = ProcessConfig.builder()
//忽略表名
.ignoreTableName(ignoreTableName)
//忽略表前綴
.ignoreTablePrefix(ignorePrefix)
//忽略表后綴
.ignoreTableSuffix(ignoreSuffix).build();
//配置
Configuration config = Configuration.builder()
//版本
.version("1.0.0")
//描述
.description("數(shù)據(jù)庫(kù)設(shè)計(jì)文檔生成")
//數(shù)據(jù)源
.dataSource(dataSource)
//生成配置
.engineConfig(engineConfig)
//生成配置
.produceConfig(processConfig).build();
//執(zhí)行生成
new DocumentationExecute(config).execute();
}
Maven 插件
<build>
<plugins>
<plugin>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-maven-plugin</artifactId>
<version>${lastVersion}</version>
<dependencies>
<!-- HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
<!--mysql driver-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
</dependencies>
<configuration>
<!--username-->
<username>root</username>
<!--password-->
<password>password</password>
<!--driver-->
<driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>
<!--jdbc url-->
<jdbcUrl>jdbc:mysql://127.0.0.1:3306/xxxx</jdbcUrl>
<!--生成文件類型-->
<fileType>HTML</fileType>
<!--打開文件輸出目錄-->
<openOutputDir>false</openOutputDir>
<!--生成模板-->
<produceType>freemarker</produceType>
<!--描述-->
<description>數(shù)據(jù)庫(kù)文檔生成</description>
<!--版本-->
<version>${project.version}</version>
<!--標(biāo)題-->
<title>數(shù)據(jù)庫(kù)文檔</title>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
參與貢獻(xiàn)
懇請(qǐng)的希望有興趣的同學(xué)能夠參與到screw建設(shè)中來,讓我們共同完善它,讓我們共同成長(zhǎng),幫助更多開發(fā)者,解決更多的問題。
