Registry / database / orm-ts

orm-ts

JSON →
library0.5.13jsnpmunverified

A TypeScript-first ORM library for Node.js (v0.5.13) that provides a declarative repository pattern with decorators for model mapping, lazy injection, caching, and validation. It integrates with dependency injection and supports MySQL (via mysql2). The library emphasizes CRUD simplicity with decorator-driven SQL binding, but is relatively niche with sparse documentation and maintenance. Key differentiators include built-in cache put/evict decorators and a base repository class.

npm install orm-ts
INSTALL
IMPORT
SIG · ORM-TS
O
orm-ts
databasejavascriptv0.5.13
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 'orm-ts'
const BaseRepository = require('orm-ts').BaseRepository
ESM-only; require is not supported.
repository decorator
import { repository } from 'orm-ts'
import { Repository } from 'orm-ts'
The exported symbol is lowercase 'repository' as a decorator function.
BaseModel
import { BaseModel } from 'orm-ts'
Used as a base class for entity models.

Creates a UserModel entity and UserRepository using orm-ts decorators, then queries by username.

import 'reflect-metadata'; import { BaseRepository, BaseModel, repository } from 'orm-ts'; class UserModel extends BaseModel { id: number; username: string; } @repository(UserModel) class UserRepository extends BaseRepository<UserModel> { async findByUsername(name: string) { return this.query(`SELECT * FROM user WHERE username = ?`, [name]); } } async function main() { const repo = new UserRepository(); const user = await repo.findByUsername('john'); console.log(user); } main();
Debug
Known issues
gotchaThe package requires reflect-metadata to be imported at the entry point before any decorator usage.
fix
Add 'import "reflect-metadata"' as the first import in your application.
affects: >=0.0.0
gotchaThe repository decorator expects a class extending BaseModel; passing a plain object will throw at runtime.
fix
Ensure all models extend BaseModel.
affects: >=0.0.0
gotchaQuery methods use positional parameters with # placeholder syntax, not named parameters.
fix
Use #param# syntax in SQL strings and pass arguments in order.
affects: >=0.0.0
deprecatedThe package has not been updated since 2019; Node.js >=6 is outdated and may cause compatibility issues.
fix
Consider migrating to a more active ORM like TypeORM or MikroORM.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot read property 'getMetadata' of undefined
reflect-metadata not imported before using orm-ts decorators.
fix
Add 'import "reflect-metadata"' at the top of your entry file.
TypeError: Class constructor BaseModel cannot be invoked without 'new'
Model class does not extend BaseModel.
fix
Extend BaseModel in your entity class.
Query failed: ER_PARSE_ERROR: You have an error in your SQL syntax
Incorrect use of # placeholder syntax or missing comma.
fix
Ensure SQL string uses #param# and arguments are passed correctly.
Upgrade
Version history
0.5.13latest on npm
Audit
Dependencies
reflect-metadatarequiredrequired for decorator metadata reflection
mysql2requireddefault MySQL database driver
inversifyoptionaldependency injection container used in examples
Agent activity
4 hits · last 30 days
node
4
Resources
packageorm-ts
orm-ts — npm install orm-ts · libregistry