-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: closure table custom naming (#7120)
* add metadata to @Tree * add simple test * ref column naming from string to callback(column)=>name * fix Closure junction metadata builder * fix ClosureSubjectExecutor columns naming * ref ClosureSubjectExecutor columns naming * fix ClosureEntityMetadataBuilder * add tests * fix test name * doc: add closure-table custom naming docs. * refactor: small code-style changing. * refactor: minor refactoring during code review Co-authored-by: alexey2baranov <Ir1n@gh>
- Loading branch information
1 parent
efc2837
commit bcd998b
Showing
9 changed files
with
270 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
import {getMetadataArgsStorage} from "../../"; | ||
import {TreeMetadataArgs} from "../../metadata-args/TreeMetadataArgs"; | ||
import {TreeType} from "../../metadata/types/TreeTypes"; | ||
import {ClosureTreeOptions} from "../../metadata/types/ClosureTreeOptions"; | ||
|
||
/** | ||
* Marks entity to work like a tree. | ||
* Tree pattern that will be used for the tree entity should be specified. | ||
* @TreeParent decorator must be used in tree entities. | ||
* TreeRepository can be used to manipulate with tree entities. | ||
*/ | ||
export function Tree(type: TreeType): ClassDecorator { | ||
export function Tree(type: TreeType, options?: ClosureTreeOptions): ClassDecorator { | ||
return function (target: Function) { | ||
|
||
getMetadataArgsStorage().trees.push({ | ||
target: target, | ||
type: type | ||
type: type, | ||
options: type === "closure-table" ? options : undefined | ||
} as TreeMetadataArgs); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Tree type. | ||
* Specifies what table pattern will be used for the tree entity. | ||
*/ | ||
import {ColumnMetadata} from "../ColumnMetadata"; | ||
|
||
export interface ClosureTreeOptions { | ||
closureTableName?: string, | ||
ancestorColumnName?: (column: ColumnMetadata) => string, | ||
descendantColumnName?: (column: ColumnMetadata) => string, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
import {Column} from "../../../../src/decorator/columns/Column"; | ||
import {TreeParent} from "../../../../src/decorator/tree/TreeParent"; | ||
import {TreeChildren} from "../../../../src/decorator/tree/TreeChildren"; | ||
import {Entity} from "../../../../src/decorator/entity/Entity"; | ||
import {Tree} from "../../../../src/decorator/tree/Tree"; | ||
|
||
@Entity() | ||
@Tree("closure-table", { | ||
closureTableName: "category_xyz_closure", | ||
ancestorColumnName: (column) => "ancestor_xyz_" + column.propertyName, | ||
descendantColumnName: (column) => "descendant_xyz_" + column.propertyName, | ||
}) | ||
export class Category { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
name: string; | ||
|
||
@TreeParent() | ||
parentCategory: Category; | ||
|
||
@TreeChildren({cascade: true}) | ||
childCategories: Category[]; | ||
|
||
// @TreeLevelColumn() | ||
// level: number; | ||
} |
Oops, something went wrong.