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.
MySQLDriver
✓ import { MySQLDriver } from 'tsbean-driver-mysql'
✗ const MySQLDriver = require('tsbean-driver-mysql')
ESM or TypeScript: named import. CommonJS require works but is not recommended.
type MySQLDriverConfig
✓ import type { MySQLDriverConfig } from 'tsbean-driver-mysql'
✗ import { MySQLDriverConfig } from 'tsbean-driver-mysql'
For type-only imports, use `import type` to avoid bundling issues in TypeScript.
DataModel
✓ import { DataModel, DataFinder, GenericRow, enforceType, DataSource } from 'tsbean-orm'
✗ import { DataModel } from 'tsbean-driver-mysql'
DataModel and related utilities are from tsbean-orm, not this driver.
Creates a MySQL data source using environment variables for connection parameters, registers it as the default data source with TSBean-ORM.
import { DataSourceDriver, DataSource } from 'tsbean-orm';
import { MySQLDriver } from 'tsbean-driver-mysql';
const mySource = MySQLDriver.createDataSource({
host: process.env.MYSQL_HOST ?? 'localhost',
port: parseInt(process.env.MYSQL_PORT ?? '3306'),
user: process.env.MYSQL_USER ?? 'root',
password: process.env.MYSQL_PASSWORD ?? '',
database: process.env.MYSQL_DATABASE ?? 'my_database',
});
DataSource.set(DataSource.DEFAULT, mySource);
export { DataSource };
Errors
Common errors & fixes
Cannot find module 'tsbean-driver-mysql'
Package not installed or missing peer dependency tsbean-orm.
fixRun `npm install tsbean-driver-mysql tsbean-orm@3.0.0`
TypeError: MySQLDriver.createDataSource is not a function
Incorrect import (e.g., default instead of named import).
fixUse `import { MySQLDriver } from 'tsbean-driver-mysql'` Error: ER_BAD_DB_ERROR: Unknown database '...'
Database name does not exist or connection config missing.
fixEnsure the database exists and `database` property is correctly set in the connection options.
Audit
Dependencies
tsbean-ormrequiredPeer dependency: core ORM library required to use this driver.