human-readable-mysql-schema-generator
v1.0.4
Published
A tool to generate a human-readable MySQL database schema in a text file
Maintainers
Readme
Human Readable MySQL Schema Generator
A Node.js package to generate a human-readable MySQL database schema in a text file.
Installation
npm install -g human-readable-mysql-schema-generatorUsage
CLI
Run the command to generate a schema file. If you don’t provide flags, you’ll be prompted for inputs:
human-readable-mysql-schema-generator [--host <host>] [--port <port>] [--user <user>] [--password <password>] [--database <database>] [--output <file>]Example (interactive mode):
human-readable-mysql-schema-generatorYou’ll be prompted:
Enter MySQL host (default: localhost): localhost
Enter MySQL port (default: 3306): 3306
Enter MySQL user: root
Enter MySQL password (can be empty): [hidden input]
Enter MySQL database name: convoaidbExample (with flags):
human-readable-mysql-schema-generator --host localhost --port 3306 --user root --password "" --database convoaidb --output schema.txtProgrammatic Usage
Provide a MySQL connection object (e.g., from mysql2, installed separately):
const mysql = require("mysql2/promise");
const { exportSchema } = require("human-readable-mysql-schema-generator");
async function run() {
const connection = await mysql.createConnection({
host: "localhost",
port: 3306,
user: "root",
password: "",
database: "mydb",
});
try {
await exportSchema(connection, "mydb", "schema.txt");
} finally {
await connection.end();
}
}
run();Generated Output Example
The generated schema_readable.txt file will look like this for a sample database:
🗂️ Table: users
Columns:
- id: int primary key auto_increment
- username: varchar(50) not null
- email: varchar(100)
- created_at: timestamp
Relationships:
- None
🗂️ Table: orders
Columns:
- order_id: int primary key auto_increment
- user_id: int not null
- created_at: timestamp
Relationships:
- user_id references id in table users [onDelete(CASCADE)]Requirements
- Node.js >= 14
- MySQL server
mysql2(for CLI or programmatic usage, installed separately)
License
MIT
