@e22m4u/js-repository-decorators
v0.0.6
Published
TypeScript decorators for @e22m4u/js-repository
Downloads
339
Readme
@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);
// {
// "name": "User",
// "tableName": "myUserTable",
// "datasource": "myDatasource",
// "properties": {
// "id": {
// "type": "string",
// "primaryKey": true,
// },
// "name": {
// "type": "string",
// "required": true,
// },
// "roleId": {
// "type": "string",
// "default": "",
// },
// },
// "relations": {
// "role": {
// "type": "belongsTo",
// "model": "Role"
// },
// },
// },
Tests
npm run test
License
MIT