Databases 5 min read

Boost Your DB Docs: How Screw Auto‑Generates Database Documentation

This article introduces Screw, a tool that automatically generates database documentation in HTML, Word, or Markdown for many popular databases, and shows how to integrate it with Maven and Java in just two simple steps.

Programmer DD
Programmer DD
Programmer DD
Boost Your DB Docs: How Screw Auto‑Generates Database Documentation

Hello, I'm TJ, a programmer who often writes documentation besides code.

If you still write database table documentation manually, consider using Screw, an automatic documentation generator.

Why the name "Screw"?

The author was inspired by the spirit of Lei Feng's screw, symbolizing a small but essential component.

Screw currently supports many databases, including MySQL, MariaDB, TiDB, Oracle, SQL Server, PostgreSQL, Cache DB, and in development: H2, DB2, HSQL, SQLite, etc.

The generated documentation can be output as HTML, Word, or Markdown.

Below are example outputs:

Using Screw is simple in two steps:

1. Add Maven dependency:

<dependency>
    <groupId>cn.smallbun.screw</groupId>
    <artifactId>screw-core</artifactId>
    <version>${lastVersion}</version>
</dependency>

2. Add Java code to configure and execute documentation generation:

/** Document generation */
void documentGeneration() {
    // Data source
    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");
    // Enable table remarks
    hikariConfig.addDataSourceProperty("useInformationSchema", "true");
    hikariConfig.setMinimumIdle(2);
    hikariConfig.setMaximumPoolSize(5);
    DataSource dataSource = new HikariDataSource(hikariConfig);
    // Engine config
    EngineConfig engineConfig = EngineConfig.builder()
            .fileOutputDir(fileOutputDir)
            .openOutputDir(true)
            .fileType(EngineFileType.HTML)
            .produceType(EngineTemplateType.freemarker)
            .fileName("CustomFileName")
            .build();
    // Ignore tables
    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()
            .designatedTableName(new ArrayList<>())
            .designatedTablePrefix(new ArrayList<>())
            .designatedTableSuffix(new ArrayList<>())
            .ignoreTableName(ignoreTableName)
            .ignoreTablePrefix(ignorePrefix)
            .ignoreTableSuffix(ignoreSuffix)
            .build();
    Configuration config = Configuration.builder()
            .version("1.0.0")
            .description("Database design document generation")
            .dataSource(dataSource)
            .engineConfig(engineConfig)
            .produceConfig(processConfig)
            .build();
    new DocumentationExecute(config).execute();
}

The project is hosted at https://gitee.com/leshalv/screw.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaSQLmaven
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.