diff --git a/docs/command-line-tools.md b/docs/command-line-tools.md index 197085075..0bc40df91 100644 --- a/docs/command-line-tools.md +++ b/docs/command-line-tools.md @@ -1,3 +1,12 @@ ## Command Line Tools -TBD \ No newline at end of file +TODO: first need to create gulp package and tasks to perform following command line operations: + +* create a schema +* update a schema +* drop a schema +* create entity +* create subscriber +* create custom repository? +* create a backup? +* ..... \ No newline at end of file diff --git a/docs/decorators-reference.md b/docs/decorators-reference.md index 100732dec..9b584650b 100644 --- a/docs/decorators-reference.md +++ b/docs/decorators-reference.md @@ -1,3 +1,196 @@ ## Decorators Reference -TBD \ No newline at end of file +* Table Decorators + * [@Table](#table) + * [@AbstractTable](#abstract-table) +* Column Decorators + * [@Column](#column) + * [@PrimaryColumn](#primary-column) + * [@CreateDateColumn](#create-date-column) + * [@UpdateDateColumn](#update-date-column) +* Relation Decorators + * [@OneToOne](#one-to-one) + * [@OneToOneInverse](#one-to-one-inverse) + * [@ManyToOne](#many-to-one) + * [@OneToMany](#one-to-many) + * [@ManyToMany](#many-to-many) + * [@ManyToManyInverse](#many-to-many-inverse) +* Subscriber and Listener Decorators + * [@OrmEventSubscriber](#orm-event-subscriber) + * [@AfterLoad](#after-load) + * [@BeforeInsert](#before-insert) + * [@AfterInsert](#after-insert) + * [@BeforeUpdate](#before-update) + * [@AfterUpdate](#after-update) + * [@BeforeRemove](#before-remove) + * [@AfterRemove](#after-remove) +* Indices + * [@Index](#index) + * [@CompoundIndex](#compound-index) + +### Table Decorators + +#### @Table + +`@Table(name: string)` + +This decorator is used to mark classes that will be a tables. Database schema will be created for all classes +decorated with it, and Repository can be retrieved and used for it. + +#### @AbstractTable + +`@AbstractTable()` + +Allows to use columns and relations data from the inherited metadata. + +### Column Decorators + +#### @Column + +`@Column(options?: ColumnOptions)` +`@Column(type?: ColumnType, options?: ColumnOptions)` + +Column decorator is used to mark a specific class property as a table column. Only properties decorated with this +decorator will be persisted to the database when entity be saved. + +#### @PrimaryColumn + +`@PrimaryColumn(options?: ColumnOptions)` +`@PrimaryColumn(type?: ColumnType, options?: ColumnOptions)` + +Column decorator is used to mark a specific class property as a table column. Only properties decorated with this +decorator will be persisted to the database when entity be saved. Primary columns also creates a PRIMARY KEY for +this column in a db. + +#### @CreateDateColumn + +`@CreateDateColumn(options?: ColumnOptions)` + +This column will store a creation date of the inserted object. Creation date is generated and inserted only once, +at the first time when you create an object, the value is inserted into the table, and is never touched again. + +#### @UpdateDateColumn + +`@UpdateDateColumn(options?: ColumnOptions)` + +This column will store an update date of the updated object. This date is being updated each time you persist the +object. + +### Relation Decorators + +#### @OneToOne + +`@OneToOne(typeFunction: (type?: any) => Function, options?: RelationOptions)` +`@OneToOne(typeFunction: (type?: any) => Function, inverseSide?: string|((object: T) => any), options?: RelationOptions)` + +One-to-one relation allows to create direct relation between two entities. Entity1 have only one Entity2. +Entity1 is an owner of the relationship, and storages Entity1 id on its own side. + +#### @OneToOneInverse + +`@OneToOneInverse(typeFunction: (type?: any) => Function, options?: RelationOptions)` +`@OneToOneInverse(typeFunction: (type?: any) => Function, inverseSide?: string|((object: T) => any), options?: RelationOptions)` + +Inverse side of the one-to-one relation. One-to-one relation allows to create direct relation between two entities. +Entity2 have only one Entity1. Entity2 is inverse side of the relation on Entity1. Does not storage id of the +Entity1. Entity1's id is storage on the one-to-one owner side. + +#### @ManyToOne + +`@ManyToOne(typeFunction: (type?: any) => Function, options?: RelationOptions)` +`@ManyToOne(typeFunction: (type?: any) => Function, inverseSide?: string|((object: T) => any), options?: RelationOptions)` + +Many-to-one relation allows to create type of relation when Entity1 can have single instance of Entity2, but +Entity2 can have a multiple instances of Entity1. Entity1 is an owner of the relationship, and storages Entity2 id +on its own side. + +#### @OneToMany + +`@OneToMany(typeFunction: (type?: any) => Function, options?: RelationOptions)` +`@OneToMany(typeFunction: (type?: any) => Function, inverseSide?: string|((object: T) => any), options?: RelationOptions)` + +One-to-many relation allows to create type of relation when Entity2 can have multiple instances of Entity1. +Entity1 have only one Entity2. Entity1 is an owner of the relationship, and storages Entity2 id on its own side. + +#### @ManyToMany + +`@ManyToMany(typeFunction: (type?: any) => Function, options?: RelationOptions)` +`@ManyToMany(typeFunction: (type?: any) => Function, inverseSide?: string|((object: T) => any), options?: RelationOptions)` + +Many-to-many is a type of relationship when Entity1 can have multiple instances of Entity2, and Entity2 can have +multiple instances of Entity1. To achieve it, this type of relation creates a junction table, where it storage +entity1 and entity2 ids. This is owner side of the relationship. + +#### @ManyToManyInverse + +`@ManyToManyInverse(typeFunction: (type?: any) => Function, options?: RelationOptions)` +`@ManyToManyInverse(typeFunction: (type?: any) => Function, inverseSide?: string|((object: T) => any), options?: RelationOptions)` + +Many-to-many is a type of relationship when Entity1 can have multiple instances of Entity2, and Entity2 can have +multiple instances of Entity1. To achieve it, this type of relation creates a junction table, where it storage +entity1 and entity2 ids. This is inverse side of the relationship. + +### Subscriber and Listener Decorators + +#### @OrmEventSubscriber + +`@OrmEventSubscriber()` + +Classes decorated with this decorator will listen to ORM events and their methods will be triggered when event +occurs. Those classes must implement OrmSubscriber interface. + +#### @AfterLoad + +`@AfterLoad()` + + * Calls a method on which this decorator is applied after entity is loaded. + +#### @BeforeInsert + +`@BeforeInsert()` + +Calls a method on which this decorator is applied before this entity insertion. + +#### @AfterInsert + +`@AfterInsert()` + +Calls a method on which this decorator is applied after this entity insertion. + +#### @BeforeUpdate + +`@BeforeUpdate()` + +Calls a method on which this decorator is applied before this entity update. + +#### @AfterUpdate + +`@AfterUpdate()` + +Calls a method on which this decorator is applied after this entity update. + +#### @BeforeRemove + +`@BeforeRemove()` + +Calls a method on which this decorator is applied before this entity removal. + +#### @AfterRemove + +`@AfterRemove()` + +Calls a method on which this decorator is applied after this entity removal. + +### Indices + +#### @Index + +`@Index(name?: string)` + +Fields that needs to be indexed must be marked with this decorator. + +#### @CompoundIndex + +`@CompoundIndex(fields: string[])` + +Compound indexes must be set on entity classes and must specify fields to be indexed. \ No newline at end of file diff --git a/src/decorator/columns/CreateDateColumn.ts b/src/decorator/columns/CreateDateColumn.ts index 24f070063..a1afca969 100644 --- a/src/decorator/columns/CreateDateColumn.ts +++ b/src/decorator/columns/CreateDateColumn.ts @@ -6,7 +6,7 @@ import "reflect-metadata"; /** * This column will store a creation date of the inserted object. Creation date is generated and inserted only once, - * at the first time when you create an object, the value is inserted into the table, and is never tocuhed again. + * at the first time when you create an object, the value is inserted into the table, and is never touched again. */ export function CreateDateColumn(options?: ColumnOptions): Function { return function (object: Object, propertyName: string) { diff --git a/src/decorator/listeners/OrmEventSubscriber.ts b/src/decorator/listeners/OrmEventSubscriber.ts index 7c74a5ebb..4f8dda530 100644 --- a/src/decorator/listeners/OrmEventSubscriber.ts +++ b/src/decorator/listeners/OrmEventSubscriber.ts @@ -2,7 +2,8 @@ import {defaultMetadataStorage} from "../../metadata-builder/MetadataStorage"; import {OrmEventSubscriberMetadata} from "../../metadata-builder/metadata/OrmEventSubscriberMetadata"; /** - * Subscribers that gonna listen to ORM events must be decorated with this decorator. + * Classes decorated with this decorator will listen to ORM events and their methods will be triggered when event + * occurs. Those classes must implement OrmSubscriber interface. */ export function OrmEventSubscriber() { return function (target: Function) {