{"id":42092,"library":"think-model","title":"think-model","description":"An adapter-based ORM for ThinkJS 3.x framework, providing database access with support for MySQL and other databases via adapters. Version 1.5.4 is the latest stable release; the package is mature and has low release cadence. Key differentiators include tight integration with ThinkJS, promise-based API, and support for associations, transactions, and query building. It is limited to ThinkJS ecosystem and not a standalone ORM like Sequelize or TypeORM.","status":"active","version":"1.5.4","language":"javascript","source_language":"en","source_url":"https://github.com/thinkjs/think-model","tags":["javascript","thinkjs","orm","mysql","adapter","model","typescript"],"install":[{"cmd":"npm install think-model","lang":"bash","label":"npm"},{"cmd":"yarn add think-model","lang":"bash","label":"yarn"},{"cmd":"pnpm add think-model","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"think-model is designed as a plugin for ThinkJS 3.x framework and requires ThinkJS core to function.","package":"thinkjs","optional":false},{"reason":"Database adapter abstraction layer for connecting to databases.","package":"think-db","optional":false}],"imports":[{"note":"ESM default import is preferred; CommonJS require also works but may cause issues with TypeScript.","wrong":"const thinkModel = require('think-model')","symbol":"thinkModel","correct":"import thinkModel from 'think-model'"},{"note":"Default export only; named import is incorrect.","wrong":"import { thinkModel } from 'think-model'","symbol":"thinkModel","correct":"const thinkModel = require('think-model')"},{"note":"Model is a named export for TypeScript type definitions.","wrong":"const { Model } = require('think-model')","symbol":"Model","correct":"import { Model } from 'think-model'"}],"quickstart":{"code":"import thinkModel from 'think-model';\nimport path from 'path';\nconst model = thinkModel('mysql', {\n  handle: require('think-db-mysql'),\n  database: 'test',\n  prefix: 'think_',\n  encoding: 'utf8'\n});\n// Define a user model\nclass UserModel extends model {\n  init(name = 'user', config = {}) {\n    super.init(name, config);\n    this.tableName = 'user';\n  }\n}\nconst userModel = new UserModel();\n// Query users\nuserModel.select().then(users => {\n  console.log(users);\n});","lang":"typescript","description":"Shows how to set up think-model with MySQL adapter, define a model, and run a select query."},"warnings":[{"fix":"Ensure your project is based on ThinkJS 3.x and think-model is loaded as a middleware.","message":"Must be used within ThinkJS 3.x framework; standalone use is not supported.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Switch to think-orm and its adapters for future compatibility.","message":"Built-in adapters like think-db-mysql are deprecated; use think-orm instead.","severity":"deprecated","affected_versions":">=1.4.0"},{"fix":"Use async/await or .then() for asynchronous operations.","message":"Promise-based API; callbacks not supported.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update custom model constructors to include options parameter.","message":"Breaking change in v1.3.0: Model constructor changed from (name, config) to (name, config, options).","severity":"breaking","affected_versions":">=1.3.0"},{"fix":"Call this.tablePrefix() in model methods to prepend prefix.","message":"Table prefix defined in config is not automatically applied; must use tablePrefix method.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.5.4':27 '3':11 'access':16 'adapt':6,25,80 'adapter-bas':5 'api':52 'associ':56 'base':7,51 'build':60 'cadenc':41 'databas':15,23 'differenti':43 'ecosystem':66 'framework':13 'includ':44 'integr':46 'javascript':76 'key':42 'latest':30 'like':72 'limit':63 'low':39 'matur':36 'model':3,81 'mysql':20,79 'orm':8,71,78 'packag':34 'promis':50 'promise-bas':49 'provid':14 'queri':59 'releas':32,40 'sequel':73 'stabl':31 'standalon':70 'support':18,54 'think':2 'think-model':1 'thinkj':10,48,65,77 'tight':45 'transact':57 'typeorm':75 'typescript':82 'version':26 'via':24 'x':12","created_at":"2026-06-04T18:55:34.802864+00:00","updated_at":"2026-06-04T18:55:34.802864+00:00","problems":[{"fix":"Install the adapter: npm install think-db-mysql","cause":"Missing database adapter package for MySQL.","error":"Error: Cannot find module 'think-db-mysql'"},{"fix":"Ensure model is instantiated after calling thinkModel() and database config is correct.","cause":"Model instance not properly initialized or missing database connection.","error":"TypeError: model.select is not a function"},{"fix":"Check import: import thinkModel from 'think-model' or const thinkModel = require('think-model');","cause":"ESM import or require statement missing or incorrect.","error":"ReferenceError: model is not defined"},{"fix":"Verify user, password, and host in database configuration.","cause":"Invalid MySQL credentials in config.","error":"Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'"}],"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/thinkjs/think-model#readme","github":"https://github.com/thinkjs/think-model","docs":null,"changelog":null,"pypi":null,"npm":"think-model","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-04","next_check":"2026-09-02","install_tag":null}}