Use Screw (screw) to quickly export database table structure documents

Use Screw (screw) to quickly export database table structure documents

Official website address: https://gitee.com/leshalv/screw/

There are a lot of information on the Internet. It feels that there is not much difference from the official website. It will be a bit confusing for a person who only needs to write database structure documents.
For example, I am busy with other projects, and my leader suddenly gave me a database address and a semi-finished document, asking me to help complete it as soon as possible.

Note: The header of the document exported by Screw looks like this. It cannot be changed in the code. It is estimated that it needs to be changed in the jar package. Those who want inconsistent headers should use it with caution!

Documentation generation support

html
word
markdown

Database support

MySQL
MariaDB
TIDB
Oracle
SqlServer
PostgreSQL
Cache DB (2016)

Steps:

1. Configure the jdk and maven environment.

 There are detailed steps on the Internet, Baidu.

2. Create a maven project.

 There are detailed steps on the Internet, Baidu.

3. All codes are as follows

1) pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.sun</groupId>
  <artifactId>Screw</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>Screw Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    </dependency>
    
    <!-- https://mvnrepository.com/artifact/cn.smallbun.screw/screw-core -->
<dependency>
   <groupId>cn.smallbun.screw</groupId>
    <artifactId>screw-core</artifactId>
    <version>1.0.5</version>
</dependency>
\t
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
<dependency>
    <groupId>com.zaxxer</groupId>
    <artifactId>HikariCP</artifactId>
    <version>3.4.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8 -->
<dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>12.2.0.1</version>
</dependency>
  </dependencies>
  <build>
    <finalName>Screw</finalName>
  </build>
</project>

2)Screw class

package Tool;
import cn.smallbun.screw.core.Configuration;
import cn.smallbun.screw.core.engine.EngineConfig;
import cn.smallbun.screw.core.engine.EngineFileType;
import cn.smallbun.screw.core.engine.EngineTemplateType;
import cn.smallbun.screw.core.execute.DocumentationExecute;
import cn.smallbun.screw.core.process.ProcessConfig;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;
import java.util.ArrayList;

/**
 * @description: Database design document generation
 */
public class Screw {<!-- -->

    public static void main(String[] args) {<!-- -->
      runScrew();
    }
    public static void runScrew() {<!-- -->
        //data source
    HikariConfig hikariConfig = new HikariConfig();
          hikariConfig.setDriverClassName("oracle.jdbc.driver.OracleDriver");
          hikariConfig.setJdbcUrl("jdbc:oracle:thin:@11.1.11.111:1521/oracle");
          hikariConfig.setUsername("oracle");
          hikariConfig.setPassword("oracle");
          //Settings can get tables remarks information
          hikariConfig.addDataSourceProperty("useInformationSchema", "true");
          hikariConfig.setMinimumIdle(2);
          hikariConfig.setMaximumPoolSize(5);
          DataSource dataSource = new HikariDataSource(hikariConfig);

        // generate configuration
        EngineConfig engineConfig = EngineConfig. builder()
            //Generate file path
            .fileOutputDir("d:/")
            //open Directory
            .openOutputDir(true)
            //file type
            .fileType(EngineFileType.WORD)
            //Generate template implementation
            .produceType(EngineTemplateType.freemarker)
            //custom file name
            .fileName("Database Design Document").build();

        //ignore table
        ArrayList<String> ignoreTableName = new ArrayList<>();
        ignoreTableName.add("test_user");
        ignoreTableName.add("test_group");
        //ignore table prefix
        ArrayList<String> ignorePrefix = new ArrayList<>();
        ignorePrefix.add("test_");
        //ignore table suffix
        ArrayList<String> ignoreSuffix = new ArrayList<>();
        ignoreSuffix.add("_test");
        ProcessConfig processConfig = ProcessConfig.builder()
            //Specify the generation logic. When the specified table, specified table prefix, and specified table suffix exist, the specified table will be generated, and the rest of the tables will not be generated, and the ignore table configuration will be skipped
            / / Generate according to the specified table by name
// .designatedTableName(designatedTableName);
// .designatedTableName(new ArrayList<>())
// //Generate based on table prefix
// .designatedTablePrefix(new ArrayList<>())
// // Generated according to the table suffix
// .designatedTableSuffix(new ArrayList<>())
            // ignore the table name
            .ignoreTableName(ignoreTableName)
            //ignore table prefix
            .ignoreTablePrefix(ignorePrefix)
            //ignore table suffix
            .ignoreTableSuffix(ignoreSuffix).build();
        // configuration
        Configuration config = Configuration. builder()
            //Version
            .version("1.0.0")
            //describe
            .description("Database Design Document Generation")
            //data source
            .dataSource(dataSource)
            // generate configuration
            .engineConfig(engineConfig)
            // generate configuration
            .produceConfig(processConfig)
            .build();
        //Execute generation
        new DocumentationExecute(config).execute();
    }

}

 

Finally, on the Screw class page, right-click-Run as-Java Application. The log that appears is probably like this, and it is successful.

Finish.