Registry / database / egg-orm-mysql

egg-orm-mysql

JSON →
library0.5.3jsnpmunverified

An ORM (Object-Relational Mapping) library for Egg.js framework, designed to work seamlessly with MySQL databases. Version 0.5.3, released under the 'egg-typed-di' dependency. It provides decorators for dependency injection, lazy injection, and SQL binding to simplify database operations in TypeScript. Key differentiators: uses decorators for ORM mapping (e.g., @repository, @column, @manyToOne) and integrates tightly with Egg.js's dependency injection system. However, the package is still in early stages (pre-1.0) and is not widely adopted; users should check for potential breaking changes.

npm install egg-orm-mysql
INSTALL
IMPORT
SIG · EGG-ORM-MYSQL
E
egg-orm-mysql
databasejavascriptv0.5.3
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.

BaseRepository
import { BaseRepository } from 'egg-orm-mysql';
const { BaseRepository } = require('egg-orm-mysql');
ESM import required if using TypeScript or modern Node. CommonJS require may not work if package is ESM-only.
BaseModel
import { BaseModel } from 'egg-orm-mysql';
No common mistake for this import; ensure correct spelling.
repository
import { repository } from 'egg-orm-mysql';
import { Repository } from 'egg-orm-mysql';
The decorator is lowercase 'repository'. Using 'Repository' will result in undefined.
column
import { column } from 'egg-orm-mysql';
import { Column } from 'egg-orm-mysql';
Case-sensitive; the decorator is lowercase 'column'.
manyToOne
import { manyToOne } from 'egg-orm-mysql';
Rarely misused; ensure correct import path.

Demonstrates setting up a model with decorators, a repository class, and a service using dependency injection.

import { Application } from 'egg'; import { BaseRepository, BaseModel, repository, column, manyToOne } from 'egg-orm-mysql'; import { context, lazyInject } from 'egg-typed-di'; // Define a model class ActivityModel extends BaseModel { @column() id: number; @manyToOne('owner', UserModel, 'getByUsername') user: Promise<UserModel>; } // Define a repository @repository(ActivityModel) class ActivityRepository extends BaseRepository<ActivityModel> { async findByName(name: string) { return await this.getOne({ where: { name } }); } } // Use in a service @context() class ActivityService { @lazyInject() private activityRepository: ActivityRepository; async getActivity(id: number) { return await this.activityRepository.getById(id); } } export default (app: Application) => { app.get('/activity/:id', async (ctx) => { const service = await ctx.getContextAsync(ActivityService); ctx.body = await service.getActivity(parseInt(ctx.params.id, 10)); }); };
Debug
Known issues
gotchaThe package is pre-1.0 (version 0.5.3) and may have breaking changes between minor versions.
fix
Pin to exact version or check changelog before updating.
affects: >=0.0.0
gotchaRequires 'egg-typed-di' as a dependency; if not installed, decorators like @context, @lazyInject will be undefined.
fix
Ensure 'egg-typed-di' is installed alongside 'egg-orm-mysql'.
affects: >=0.0.0
deprecatedThe package name used to be 'egg-orm-ts' (see GitHub repo), but it is now published as 'egg-orm-mysql'. Existing imports may need updating.
fix
Change imports from 'egg-orm-ts' to 'egg-orm-mysql'.
affects: <=0.4.0
breakingDecorators like @repository and @bindSql may have different signatures or behaviors in future versions.
fix
Refer to the official documentation for the latest decorator usage.
affects: >=0.5.0
Errors
Common errors & fixes
Error: Cannot find module 'egg-typed-di'
Required peer dependency not installed.
fix
Run: npm install egg-typed-di --save
TypeError: Class extends value undefined is not a constructor or null
Missing or incorrect import of BaseModel/BaseRepository.
fix
Ensure you import BaseModel and BaseRepository from 'egg-orm-mysql'.
Cannot read property 'getById' of undefined
Repository not injected (missing @lazyInject in service or domain).
fix
Add @lazyInject() decorator to the repository property in the service/domain class.
Decorators are not valid here
Decorator syntax used without enabling experimentalDecorators in tsconfig.json.
fix
Add 'experimentalDecorators': true to tsconfig.json under compilerOptions.
Upgrade
Version history
0.5.3latest on npm
Audit
Dependencies
egg-typed-direquiredProvides the dependency injection framework (decorators like @context, @lazyInject) used by this ORM.
Agent activity
10 hits · last 30 days
node
8
Resources
egg-orm-mysql — npm install egg-orm-mysql · libregistry