typeorm#EntityMetadata TypeScript Examples

The following examples show how to use typeorm#EntityMetadata. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: uml-builder.class.ts    From typeorm-uml with MIT License 6 votes vote down vote up
/**
	 * Builds UML connection strings and returns it.
	 *
	 * @protected
	 * @param {EntityMetadata} entity An entity metadata.
	 */
	protected buildForeignKeys( entity: EntityMetadata ) {
		let uml = '';

		if ( entity.foreignKeys.length > 0 ) {
			for ( let i = 0, len = entity.foreignKeys.length; i < len; i++ ) {
				uml += this.buildForeignKey( entity.foreignKeys[i], entity );
			}
		}

		return uml;
	}
Example #2
Source File: uml-builder.class.ts    From typeorm-uml with MIT License 6 votes vote down vote up
/**
	 * Builds an UML connection string and returns it.
	 *
	 * @protected
	 * @param {ForeignKeyMetadata} foreignKey A foreign key metadata.
	 * @param {EntityMetadata} entity An entity metadata.
	 * @returns {string} An uml connection string.
	 */
	protected buildForeignKey( foreignKey: ForeignKeyMetadata, entity: EntityMetadata ): string {
		const { columns } = foreignKey;

		const zeroOrMore = 'o{';
		const oneOrMore = '|{';

		let relationship = columns.some( ( column ) => !column.isNullable ) ? oneOrMore : zeroOrMore;
		if ( columns.length === 1 && columns[0].relationMetadata?.isOneToOne ) {
			relationship = '||';
		}

		return `"${ foreignKey.referencedTablePath }" ||--${ relationship } "${ entity.tableNameWithoutPrefix }"\n`;
	}