Registry / database / think-model

think-model

JSON →
library1.5.4jsnpmunverified

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.

npm install think-model
INSTALL
IMPORT
SIG · THINK-MODEL
T
think-model
databasejavascriptv1.5.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

thinkModel
✓ import thinkModel from 'think-model'
✗ const thinkModel = require('think-model')
ESM default import is preferred; CommonJS require also works but may cause issues with TypeScript.
thinkModel
✓ const thinkModel = require('think-model')
✗ import { thinkModel } from 'think-model'
Default export only; named import is incorrect.
Model
✓ import { Model } from 'think-model'
✗ const { Model } = require('think-model')
Model is a named export for TypeScript type definitions.

Shows how to set up think-model with MySQL adapter, define a model, and run a select query.

import thinkModel from 'think-model'; import path from 'path'; const model = thinkModel('mysql', { handle: require('think-db-mysql'), database: 'test', prefix: 'think_', encoding: 'utf8' }); // Define a user model class UserModel extends model { init(name = 'user', config = {}) { super.init(name, config); this.tableName = 'user'; } } const userModel = new UserModel(); // Query users userModel.select().then(users => { console.log(users); });
Debug
Known issues
gotchaMust be used within ThinkJS 3.x framework; standalone use is not supported.
fix
Ensure your project is based on ThinkJS 3.x and think-model is loaded as a middleware.
affects: >=1.0.0
deprecatedBuilt-in adapters like think-db-mysql are deprecated; use think-orm instead.
fix
Switch to think-orm and its adapters for future compatibility.
affects: >=1.4.0
gotchaPromise-based API; callbacks not supported.
fix
Use async/await or .then() for asynchronous operations.
affects: >=1.0.0
breakingBreaking change in v1.3.0: Model constructor changed from (name, config) to (name, config, options).
fix
Update custom model constructors to include options parameter.
affects: >=1.3.0
gotchaTable prefix defined in config is not automatically applied; must use tablePrefix method.
fix
Call this.tablePrefix() in model methods to prepend prefix.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'think-db-mysql'
Missing database adapter package for MySQL.
fix
Install the adapter: npm install think-db-mysql
TypeError: model.select is not a function
Model instance not properly initialized or missing database connection.
fix
Ensure model is instantiated after calling thinkModel() and database config is correct.
ReferenceError: model is not defined
ESM import or require statement missing or incorrect.
fix
Check import: import thinkModel from 'think-model' or const thinkModel = require('think-model');
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
Invalid MySQL credentials in config.
fix
Verify user, password, and host in database configuration.
Upgrade
Version history
1.5.4latest on npm
Audit
Dependencies
thinkjsrequiredthink-model is designed as a plugin for ThinkJS 3.x framework and requires ThinkJS core to function.
think-dbrequiredDatabase adapter abstraction layer for connecting to databases.
Agent activity
17 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
think-model — npm install think-model · libregistry