{"id":43272,"library":"mysql-easy-type","title":"MySQL Easy Type","description":"MySQL Easy Type is an ORM-like library for Node.js that provides a simple, typed interface for MySQL querying with automatic TypeScript declaration generation. Version 1.23.2 is current, with stable release cadence. It wraps mysql2 to provide model-based CRUD operations, join support, transactions, and a CLI tool to generate type definitions and model files from database schema. Key differentiators include its zero-config setup, automatic type generation from the database, and a concise API with chaining methods like find, limit, join, and get. It is ideal for developers who want strong typing without writing manual schemas, and it supports both connection and pool queries.","status":"active","version":"1.23.2","language":"javascript","source_language":"en","source_url":"https://github.com/yefei/easy-model","tags":["javascript","mysql","query","model","types","generate","database"],"install":[{"cmd":"npm install mysql-easy-type","lang":"bash","label":"npm"},{"cmd":"yarn add mysql-easy-type","lang":"bash","label":"yarn"},{"cmd":"pnpm add mysql-easy-type","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency for database connectivity; the library wraps mysql2's connection and pool APIs.","package":"mysql2","optional":false}],"imports":[{"note":"The package is CommonJS only; try to import with ESM may fail unless using a bundler or dynamic import.","wrong":"import { model } from 'mysql-easy-type'; // Cannot use ESM imports directly as the package is CJS only","symbol":"model","correct":"const { model } = require('mysql-easy-type');"},{"note":"Query is for single connections, PoolQuery for pool connections. Both are named exports.","wrong":"const Query = require('mysql-easy-type').query; // Case-sensitive; must be capitalized 'Query'","symbol":"Query","correct":"const { Query, PoolQuery } = require('mysql-easy-type');"},{"note":"PoolQuery is a named export; used with mysql2 pool instances.","wrong":null,"symbol":"PoolQuery","correct":"const { PoolQuery } = require('mysql-easy-type');"}],"quickstart":{"code":"const mysql = require('mysql2');\nconst { model, Query } = require('mysql-easy-type');\n\nconst connection = mysql.createConnection({\n  host: process.env.MYSQL_HOST ?? 'localhost',\n  user: process.env.MYSQL_USER ?? 'root',\n  database: process.env.MYSQL_DATABASE ?? 'test',\n  password: process.env.MYSQL_PASSWORD ?? ''\n});\n\nconst query = new Query(connection);\nconst User = model('user');\n\nasync function main() {\n  // Create a user\n  const id = await User(query).create({ name: 'John', age: 30 });\n  console.log('Created user with id:', id);\n\n  // Find and update\n  const user = await User(query).findByPk(id);\n  user.name = 'Jane';\n  await user.save();\n\n  // Query with filter\n  const users = await User(query).find({ age: 30 }).all();\n  console.log('Users:', users);\n\n  // Count\n  const count = await User(query).count();\n  console.log('Total users:', count);\n\n  connection.end();\n}\n\nmain().catch(console.error);","lang":"javascript","description":"Shows basic CRUD operations: creating a user, finding by primary key, updating, querying with filter, and counting records."},"warnings":[{"fix":"Use PoolQuery for mysql2 pool: const { PoolQuery } = require('mysql-easy-type'); const query = new PoolQuery(pool);","message":"The Query class requires a mysql2 connection object; using a pool connection requires PoolQuery, not Query.","severity":"gotcha","affected_versions":"all"},{"fix":"Always pass the query instance: const User = model('user'); const result = await User(query).find().all();","message":"The model() function returns a function that takes a query instance; you must call it with query each time: User(query).find()","severity":"gotcha","affected_versions":"all"},{"fix":"Use require or use dynamic import: const { model } = await import('mysql-easy-type');","message":"The package uses CommonJS; ESM imports like import { model } from 'mysql-easy-type' are not supported directly and may break in Node ESM environments.","severity":"deprecated","affected_versions":"all"},{"fix":"Install dotenv and mysql2 as devDependencies: npm i dotenv mysql2 --save-dev; ensure .env file has all required vars.","message":"The CLI command 'mysqleasytype' requires dotenv and mysql2 as dev dependencies and a .env file with MYSQL_* variables. Missing these will cause silent failures.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Update join calls: .join(Message, { fk: 'id', ref: 'user_id', asList: true })","message":"Join syntax changed: previous version used a different join signature. Ensure you are using the current format with fk, ref, asList.","severity":"breaking","affected_versions":"<1.20"}],"env_vars":null,"search_vec":"'1.23.2':30 'api':81 'automat':25,72 'base':44 'cadenc':36 'chain':83 'cli':52 'concis':80 'config':70 'connect':108 'crud':45 'current':32 'databas':62,77,118 'declar':27 'definit':57 'develop':95 'differenti':65 'easi':2,5 'file':60 'find':86 'generat':28,55,74,117 'get':90 'ideal':93 'includ':66 'interfac':20 'javascript':112 'join':47,88 'key':64 'librari':12 'like':11,85 'limit':87 'manual':102 'method':84 'model':43,59,115 'model-bas':42 'mysql':1,4,22,113 'mysql2':39 'node.js':14 'oper':46 'orm':10 'orm-lik':9 'pool':110 'provid':16,41 'queri':23,111,114 'releas':35 'schema':63,103 'setup':71 'simpl':18 'stabl':34 'strong':98 'support':48,106 'tool':53 'transact':49 'type':3,6,19,56,73,99,116 'typescript':26 'version':29 'want':97 'without':100 'wrap':38 'write':101 'zero':69 'zero-config':68","created_at":"2026-06-05T16:59:00.488105+00:00","updated_at":"2026-06-05T16:59:00.488105+00:00","problems":[{"fix":"npm install mysql-easy-type","cause":"Package not installed or not in node_modules","error":"Error: Cannot find module 'mysql-easy-type'"},{"fix":"Use: const user = await User(query).findByPk(1);","cause":"model('user') returns a function, but you forgot to call it with the query instance","error":"TypeError: User is not a function"},{"fix":"Use a pool instead of single connection: const pool = mysql.createPool({...}); const query = new PoolQuery(pool);","cause":"MySQL connection timed out or was closed after inactivity","error":"Error: Connection lost: The server closed the connection"},{"fix":"npm install dotenv --save-dev","cause":"dotenv is required for the CLI generator but not installed","error":"Error: Cannot find module 'dotenv'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/yefei/easy-model#readme","github":"https://github.com/yefei/easy-model","docs":null,"changelog":null,"pypi":null,"npm":"mysql-easy-type","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}