Introduction to the

In enterprise-level development, we often have to write database table structure documents of the time to pay, since the start of the industry, to several enterprises, about the database table structure document status: Either not, or have, but are handwritten, late operation and maintenance development, need manual maintenance to the document, is very tedious, if you forget a maintenance, will cause a lot of trouble to the later work, virtually created a lot of pits for themselves and posterity, so need a plug-in tool SCREW [1] to maintain.

Characteristics of screw

  • Simple, lightweight and well designed. You don’t need powerDesigner as a heavy modeling tool
  • Multiple database support. Supports common databases such as MySQL, Oracle, and SqlServer
  • Document in multiple formats. Supports MD, HTML, and WORD
  • Flexible scalability. Support for user-defined templates and presentation styles

Supported database types

[✔ ️] MySQL [✔ ️] MariaDB [✔ ️] TIDB [✔ ️] Oracle [✔ ️] used to [✔ ️] PostgreSQL [✔ ️] Cache DB

Rely on

Take the mysQL8 database as an example

<! -- Database document core dependencies -->  <dependency>
      <groupId>cn.smallbun.screw</groupId>
      <artifactId>screw-core</artifactId>
The < version > 1.0.3 < / version > </dependency> <! -- HikariCP --> <dependency>  <groupId>com.zaxxer</groupId>  <artifactId>HikariCP</artifactId> The < version > 3.4.5 < / version > </dependency> <! --mysql driver--> <dependency>  <groupId>mysql</groupId>  <artifactId>mysql-connector-java</artifactId> The < version > 8.0.20 < / version > </dependency> Copy the code

1. Configure document generation through custom code

@Test
public void shouldAnswerWithTrue(a) {
    / / the data source
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
 hikariConfig.setJdbcUrl("JDBC: mysql: / / 127.0.0.1:3306 / test");  hikariConfig.setUsername("root");  hikariConfig.setPassword("root");  // Set to get tables Remarks  hikariConfig.addDataSourceProperty("useInformationSchema"."true");  hikariConfig.setMinimumIdle(2);  hikariConfig.setMaximumPoolSize(5);  DataSource dataSource = new HikariDataSource(hikariConfig);  // Build the configuration  EngineConfig engineConfig = EngineConfig.builder()  // Generate file path  .fileOutputDir("/Users/lengleng")  // Open the directory  .openOutputDir(true)  // File type  .fileType(EngineFileType.HTML)  // Generate template implementation  .produceType(EngineTemplateType.freemarker).build();   / / ignore list  ArrayList<String> ignoreTableName = new ArrayList<>();  ignoreTableName.add("test_user");  ignoreTableName.add("test_group");  // Ignore the table prefix  ArrayList<String> ignorePrefix = new ArrayList<>();  ignorePrefix.add("test_");  // Ignore the table suffix  ArrayList<String> ignoreSuffix = new ArrayList<>();  ignoreSuffix.add("_test");  ProcessConfig processConfig = ProcessConfig.builder()  // Ignore the table name  .ignoreTableName(ignoreTableName)  // Ignore the table prefix  .ignoreTablePrefix(ignorePrefix)  // Ignore the table suffix  .ignoreTableSuffix(ignoreSuffix).build();  / / configuration  Configuration config = Configuration.builder()  / / version  .version("1.0.0")  / / description  .description("Database Design Document Generation")  / / the data source  .dataSource(dataSource)  // Build the configuration  .engineConfig(engineConfig)  // Build the configuration  .produceConfig(processConfig).build();  // Perform the build  new DocumentationExecute(config).execute(); } Copy the code

2. Generate documents through plug-ins

<build>
    <plugins>
        <plugin>
            <groupId>cn.smallbun.screw</groupId>
            <artifactId>screw-maven-plugin</artifactId>
The < version > 1.0.2 < / version > <dependencies> <! -- HikariCP --> <dependency>  <groupId>com.zaxxer</groupId>  <artifactId>HikariCP</artifactId> The < version > 3.4.5 < / version > </dependency> <! --mysql driver--> <dependency>  <groupId>mysql</groupId>  <artifactId>mysql-connector-java</artifactId> The < version > 8.0.20 < / version > </dependency>  </dependencies>  <configuration> <! --username--> <username>root</username> <! --password--> <password>root</password> <! --driver--> <driverClassName>com.mysql.cj.jdbc.Driver</driverClassName> <! --jdbc url-->< jdbcUrl > JDBC: mysql: / / 127.0.0.1:3306 /test</jdbcUrl> <! -- Generate file type --> <fileType>HTML</fileType> <! -- File output directory --> <fileOutputDir>/Users/lengleng</fileOutputDir> <! -- Open file output directory --> <openOutputDir>false</openOutputDir> <! Create a template --> <produceType>freemarker</produceType> <! - description -- -- ><description> Database document generation </description><! -- version -- -- > <version>${project.version}</version> <! - the title -- -- ><title> Database document </title> </configuration>  <executions>  <execution>  <phase>compile</phase>  <goals>  <goal>run</goal>  </goals>  </execution>  </executions>  </plugin>  </plugins> </build> Copy the code

The resources

[1]

screw: https://gitee.com/leshalv/screw