0.0.7 • Published 11 months ago

@e22m4u/js-repository-decorators v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@e22m4u/js-repository-decorators

TypeScript декораторы для @e22m4u/js-repository

Установка

npm install @e22m4u/js-repository-decorators

Поддержка декораторов

Для включения поддержки декораторов, добавьте указанные ниже опции в файл tsconfig.json вашего проекта.

{
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true
}

Пример

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"
//     },
//   },
// },

Тесты

npm run test

Лицензия

MIT

0.0.7

11 months ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago