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.
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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
