{"id":17945,"library":"sequelize-automate","title":"Sequelize Automate Model Generator","description":"sequelize-automate is a utility designed to automatically generate Sequelize ORM model definitions directly from an existing database schema. It supports various code styles including JavaScript, TypeScript, Egg.js, and Midway.js for the generated models. The package is currently at version 1.2.2 and appears to be actively maintained, though it does not specify a fixed release cadence. Its key differentiator is its straightforward command-line interface (CLI) that simplifies scaffolding models from an established database, reducing the manual boilerplate required when integrating Sequelize into existing projects. It supports popular SQL dialects such as MySQL, PostgreSQL, MariaDB, SQLite, and Microsoft SQL Server, requiring users to install the corresponding database driver separately. This tool is particularly useful for accelerating development in brownfield projects or when rapidly prototyping a Sequelize application against an existing data source.","status":"active","version":"1.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/nodejh/sequelize-automate","tags":["javascript","mysql","postgres","sequelize","sequelizejs","mapper"],"install":[{"cmd":"npm install sequelize-automate","lang":"bash","label":"npm"},{"cmd":"yarn add sequelize-automate","lang":"bash","label":"yarn"},{"cmd":"pnpm add sequelize-automate","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core ORM library for which models are generated.","package":"sequelize","optional":false},{"reason":"PostgreSQL database driver (required for PostgreSQL dialect).","package":"pg","optional":true},{"reason":"Required by pg for hstore support in PostgreSQL.","package":"pg-hstore","optional":true},{"reason":"MySQL database driver (required for MySQL/MariaDB dialects).","package":"mysql2","optional":true},{"reason":"MariaDB database driver (alternative for MySQL/MariaDB dialects).","package":"mariadb","optional":true},{"reason":"SQLite database driver (required for SQLite dialect).","package":"sqlite3","optional":true},{"reason":"Microsoft SQL Server database driver (required for MSSQL dialect).","package":"tedious","optional":true}],"imports":[{"note":"The primary programmatic interface is the `Automate` class. Use `new Automate(database, user, pass, options)` to configure, then `.run()` or `.getDefinitions()` methods.","symbol":"Automate","correct":"import Automate from 'sequelize-automate'; // ESM\nconst Automate = require('sequelize-automate'); // CJS"},{"note":"The `run` method is an instance method and must be called on an instantiated `Automate` object, not directly on the class. It generates and returns the model code.","wrong":"Automate.run();","symbol":"AutomateInstance.run","correct":"const automate = new Automate(database, user, pass, options);\nconst generatedCode = await automate.run();"},{"note":"Similar to `run`, `getDefinitions` is an instance method for retrieving raw table definitions before code generation.","wrong":"Automate.getDefinitions();","symbol":"AutomateInstance.getDefinitions","correct":"const automate = new Automate(database, user, pass, options);\nconst definitions = await automate.getDefinitions();"}],"quickstart":{"code":"import { exec } from 'child_process';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\n// Database connection details from environment variables or defaults\nconst DB_HOST = process.env.DB_HOST ?? 'localhost';\nconst DB_NAME = process.env.DB_NAME ?? 'your_database_name';\nconst DB_USER = process.env.DB_USER ?? 'root';\nconst DB_PASSWORD = process.env.DB_PASSWORD ?? '';\nconst DB_PORT = process.env.DB_PORT ?? '3306'; // e.g., '5432' for Postgres\nconst DB_DIALECT = process.env.DB_DIALECT ?? 'mysql'; // e.g., 'postgres', 'sqlite', 'mssql'\nconst OUTPUT_DIR = path.join(__dirname, 'generated_models');\n\n// Ensure output directory exists (for a real project, consider `fs.mkdirSync`)\nconsole.log(`Models will be generated in: ${OUTPUT_DIR}`);\n\n// CLI command to generate TypeScript models\nconst command = `npx sequelize-automate \\\n  --type ts \\\n  --host ${DB_HOST} \\\n  --database ${DB_NAME} \\\n  --user ${DB_USER} \\\n  --password ${DB_PASSWORD} \\\n  --port ${DB_PORT} \\\n  --dialect ${DB_DIALECT} \\\n  --output ${OUTPUT_DIR} \\\n  --camel`;\n\nconsole.log(`Executing command:\\n${command}`);\n\nexec(command, (error, stdout, stderr) => {\n  if (error) {\n    console.error(`Error generating models: ${error.message}`);\n    return;\n  }\n  if (stderr) {\n    console.error(`stderr: ${stderr}`);\n  }\n  console.log(`Models generated successfully:\\n${stdout}`);\n  console.log(`\nCheck the '${OUTPUT_DIR}' directory for your new Sequelize models.`);\n});","lang":"typescript","description":"This quickstart demonstrates how to use `sequelize-automate` via its command-line interface (CLI) to generate TypeScript-based Sequelize models from an existing database schema. It utilizes environment variables for secure database connection details and outputs the generated files to a specified directory."},"warnings":[{"fix":"Ensure you explicitly run `npm install sequelize` and `npm install <your-database-driver>` (e.g., `npm install mysql2`) in your project.","message":"Starting with `sequelize-automate` v1.x, `sequelize` itself and database drivers (e.g., `mysql2`, `pg`) are no longer direct dependencies. Users must manually install `sequelize` and the appropriate dialect binding in their project.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Initialize the `Automate` class like `new Automate(database, user, password, { host, port, dialect, ...options })` ensuring all necessary connection details are provided.","message":"When using `sequelize-automate` programmatically, ensure you correctly instantiate the `Automate` class with all required database connection parameters. Incorrect or missing parameters will lead to connection failures.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Specify the correct `--type` option for your project's needs. If using `--type ts`, ensure your project's `tsconfig.json` is configured correctly and you have TypeScript 4.x+ installed.","message":"The `--type` option dictates the generated code style (e.g., `js`, `ts`, `egg`, `midway`). If generating TypeScript models (`--type ts`), you will need TypeScript 4.x or later to compile the generated files.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"After generation, review the models and manually add any missing associations or custom logic within your application's Sequelize setup.","message":"Generated models from `sequelize-automate` provide basic schema definitions. Complex associations (e.g., `hasMany`, `belongsToMany`) and custom methods are not automatically inferred or generated and may require manual addition post-generation.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Run `npm install mysql2` (or `npm install -g mysql2` if using the global CLI) to install the necessary driver. Replace `mysql2` with `pg`, `mariadb`, `sqlite3`, or `tedious` for other dialects.","cause":"The required database driver for MySQL/MariaDB (mysql2) is not installed in the project or globally.","error":"Error: Please install mysql2 package manually."},{"fix":"Verify that your database server is running and accessible from the machine running `sequelize-automate`. Double-check the `--host`, `--port`, `--user`, and `--password` parameters. Check firewall rules.","cause":"The application could not establish a connection to the database. This typically means the database server is not running, the host/port is incorrect, or a firewall is blocking the connection.","error":"Error: connect ECONNREFUSED <host>:<port>"},{"fix":"Ensure the `--user` and `--password` arguments are correct and that the user has sufficient privileges to read the database schema.","cause":"The provided database credentials (username and password) are incorrect or lack the necessary permissions to access the specified database.","error":"Error: Can't get definitions from database. Reason: Access denied for user '...'@'localhost' (using password: YES)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}