mysql-factory2 is a simple ORM for MySQL, ported from an internal project to open-source. Version 2.1.4 is the latest stable release, with maintenance updates since 2022. It provides a model-based approach to CRUD operations on MySQL tables, offering an alternative to heavier ORMs like Sequelize. The package is ESM-only for Node.js environments (>=10) and is available on npm as mysql-factory2 due to login issues with the original mysql-factory package. It wraps all field definitions with backticks to prevent reserved word collisions and includes basic query filtering options.
npm install mysql-factory2No compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates creating a MySQLFactory instance, defining a model with schema, inserting a record, and querying by name.
Upgrade Node.js to version 10 or higher. Older versions are not supported.
Use mysql-factory2 instead of mysql-factory in package.json.
Use import syntax and ensure package.json has "type": "module" or use .mjs extension.
Use import MySQLFactory from 'mysql-factory2' (no curly braces).
Update schema to { field: { type: 'string', key: true } } format; old array syntax removed.Pass connection settings when instantiating MySQLFactory.
Run 'npm install mysql-factory2' (note the '2' suffix). Install mysql as a peer dependency.
Use dynamic import or switch to ESM: const MySQLFactory = (await import('mysql-factory2').default;Upgrade to mysql-factory2@2.1.3 or newer which wraps all field names with backticks.