Registry / database / sequelize-automate

sequelize-automate

JSON →
library1.2.2jsnpmunverified

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.

npm install sequelize-automate
INSTALL
IMPORT
SIG · SEQUELIZE-AUTOMATE
S
sequelize-automate
databasejavascriptv1.2.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Automate
import Automate from 'sequelize-automate'; // ESM const Automate = require('sequelize-automate'); // CJS
The primary programmatic interface is the `Automate` class. Use `new Automate(database, user, pass, options)` to configure, then `.run()` or `.getDefinitions()` methods.
AutomateInstance.run
const automate = new Automate(database, user, pass, options); const generatedCode = await automate.run();
Automate.run();
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.
AutomateInstance.getDefinitions
const automate = new Automate(database, user, pass, options); const definitions = await automate.getDefinitions();
Automate.getDefinitions();
Similar to `run`, `getDefinitions` is an instance method for retrieving raw table definitions before code generation.

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.

import { exec } from 'child_process'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // Database connection details from environment variables or defaults const DB_HOST = process.env.DB_HOST ?? 'localhost'; const DB_NAME = process.env.DB_NAME ?? 'your_database_name'; const DB_USER = process.env.DB_USER ?? 'root'; const DB_PASSWORD = process.env.DB_PASSWORD ?? ''; const DB_PORT = process.env.DB_PORT ?? '3306'; // e.g., '5432' for Postgres const DB_DIALECT = process.env.DB_DIALECT ?? 'mysql'; // e.g., 'postgres', 'sqlite', 'mssql' const OUTPUT_DIR = path.join(__dirname, 'generated_models'); // Ensure output directory exists (for a real project, consider `fs.mkdirSync`) console.log(`Models will be generated in: ${OUTPUT_DIR}`); // CLI command to generate TypeScript models const command = `npx sequelize-automate \ --type ts \ --host ${DB_HOST} \ --database ${DB_NAME} \ --user ${DB_USER} \ --password ${DB_PASSWORD} \ --port ${DB_PORT} \ --dialect ${DB_DIALECT} \ --output ${OUTPUT_DIR} \ --camel`; console.log(`Executing command:\n${command}`); exec(command, (error, stdout, stderr) => { if (error) { console.error(`Error generating models: ${error.message}`); return; } if (stderr) { console.error(`stderr: ${stderr}`); } console.log(`Models generated successfully:\n${stdout}`); console.log(` Check the '${OUTPUT_DIR}' directory for your new Sequelize models.`); });
sequelize-automate --version
Debug
Known issues
breakingStarting 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.
fix
Ensure you explicitly run `npm install sequelize` and `npm install <your-database-driver>` (e.g., `npm install mysql2`) in your project.
affects: >=1.0.0
gotchaWhen 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.
fix
Initialize the `Automate` class like `new Automate(database, user, password, { host, port, dialect, ...options })` ensuring all necessary connection details are provided.
affects: >=1.0.0
gotchaThe `--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.
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.
affects: >=1.0.0
gotchaGenerated 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.
fix
After generation, review the models and manually add any missing associations or custom logic within your application's Sequelize setup.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Please install mysql2 package manually.
The required database driver for MySQL/MariaDB (mysql2) is not installed in the project or globally.
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.
Error: connect ECONNREFUSED <host>:<port>
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.
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.
Error: Can't get definitions from database. Reason: Access denied for user '...'@'localhost' (using password: YES)
The provided database credentials (username and password) are incorrect or lack the necessary permissions to access the specified database.
fix
Ensure the `--user` and `--password` arguments are correct and that the user has sufficient privileges to read the database schema.
Upgrade
Version history
1.2.2latest on npm
Audit
Dependencies
sequelizerequiredCore ORM library for which models are generated.
pgoptionalPostgreSQL database driver (required for PostgreSQL dialect).
pg-hstoreoptionalRequired by pg for hstore support in PostgreSQL.
mysql2optionalMySQL database driver (required for MySQL/MariaDB dialects).
mariadboptionalMariaDB database driver (alternative for MySQL/MariaDB dialects).
sqlite3optionalSQLite database driver (required for SQLite dialect).
tediousoptionalMicrosoft SQL Server database driver (required for MSSQL dialect).
Agent activity
17 hits · last 30 days
node
14
Meta
2
Resources