@e22m4u/js-repository-decorators
English | Русский
TypeScript decorators for
@e22m4u/js-repository
Installation
npm install @e22m4u/js-repository-decorators
Decorator Support
To enable decorator support, add the following options
to your project's tsconfig.json
file.
{
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
Example
import {
model,
property,
relation,
getModelDefinitionFromClass,
} from '@e22m4u/js-repository-decorators';
import {DataType} from '@e22m4u/js-repository';
import {RelationType} from '@e22m4u/js-repository';
@model({
tableName: 'myUserTable',
datasource: 'myDatasource',
})
class User {
@property({
type: DataType.STRING,
primaryKey: true,
})
id!: string;
@property({
type: DataType.STRING,
required: true,
})
name!: string;
@property({
type: DataType.STRING,
default: '',
})
roleId!: string;
@relation({
type: RelationType.BELONGS_TO,
model: 'Role',
})
role?: object;
}
const modelDef = getModelDefinitionFromClass(User);
Tests
npm run test
License
MIT