Registry / database / modelar-mysql-adapter

modelar-mysql-adapter

JSON →
library3.0.7jsnpmunverified

A database adapter for the Modelar ORM/ODM framework to connect to MySQL or MariaDB databases. Current stable version is 3.0.7. It is bundled internally by Modelar (since version 3), so users typically do not install it separately. Releases are infrequent and tied to Modelar's release cycle. Key differentiator: it seamlessly integrates with Modelar's DB.init() configuration, automatically switching engine between InnoDB (MySQL) and Aria (MariaDB) and supporting transactions out of the box. It provides a thin layer over the mysql2 driver, handling connection pooling and query execution.

npm install modelar-mysql-adapter
INSTALL
IMPORT
SIG · MODELAR-MYSQL-ADAP
M
modelar-mysql-adapter
databasejavascriptv3.0.7
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.

DB
import { DB } from 'modelar'
import { DB } from 'modelar-mysql-adapter'
The adapter is internally included by Modelar; you should import DB from 'modelar', not from this package.
default export
const adapter = require('modelar-mysql-adapter')
The package exports a class internally used by Modelar. Direct usage is not recommended; it's better to configure the DB via Modelar's DB.init().
DB.init
DB.init({ type: 'mysql', database: 'mydb', host: 'localhost', port: 3306, user: 'root', password: 'pass' })
DB.init({ type: 'mysql' })
When using type 'mysql' or 'maria', the adapter is automatically loaded. Ensure all connection parameters are provided.

Shows how to use the adapter indirectly by initializing Modelar's DB with MySQL type, then querying the database.

// Install: npm install modelar // Then in your code: const { DB } = require('modelar'); DB.init({ type: 'mysql', // or 'maria' database: 'modelar', host: '127.0.0.1', port: 3306, user: 'root', password: process.env.DB_PASSWORD ?? '' }); // Use DB to query DB.query('SELECT * FROM users').then(users => { console.log(users); }).catch(err => { console.error(err); });
Debug
Known issues
gotchaDo NOT install this package separately. It is bundled with Modelar since v3, and installing it manually may cause version mismatches or duplicate instances.
fix
Remove modelar-mysql-adapter from your package.json and rely on the dependency shipped with modelar.
affects: >=3.0.0
breakingThe package name changed from 'modelar-mysql' to 'modelar-mysql-adapter' in version 3.0.0.
fix
If you had a direct dependency on 'modelar-mysql', update to 'modelar-mysql-adapter' or better remove the direct dependency and use modelar only.
affects: >=3.0.0
gotchaWhen using MariaDB, the adapter uses Aria engine instead of InnoDB. This can affect foreign key support (Aria does not support foreign keys).
fix
If you need foreign keys, use type: 'mysql' even if connecting to MariaDB? (Check Modelar docs.)
affects: >=3.0.0
Errors
Common errors & fixes
Error: Cannot find module 'modelar-mysql-adapter'
The adapter is not installed when only 'modelar' is installed? Actually it should be bundled, but if modelar is not installed, this error appears if you try to require this package directly.
fix
Install modelar: 'npm install modelar' which includes the adapter.
Error: Unknown database type: mysql
When passing type 'mysql', the adapter might not be loaded because modelar version is older than 3? Or the adapter is not properly bundled.
fix
Ensure modelar version >= 3.0.0 with 'npm list modelar'.
Upgrade
Version history
3.0.7latest on npm
Audit
Dependencies
modelarrequiredThis adapter is designed to be used as an internal dependency of Modelar and is not meant to be consumed directly.
Agent activity
4 hits · last 30 days
node
4
Resources
modelar-mysql-adapter — npm install modelar-mysql-adapter · libregistry