Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add transformer to ViewColumnOptions (#8717)
* feat: add transformer to ViewColumnOptions Added `transformer` field into ViewColumnOptions Allow view column to unmarshal by custom ValueTransformer * docs: add supported view-entity column options * updated docs Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
- Loading branch information
1 parent
32549fe
commit 96ac8f7
Showing
14 changed files
with
122 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
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,43 @@ | ||
import {Connection, ValueTransformer} from "../../../../../src"; | ||
import {ViewColumn} from "../../../../../src/decorator/columns/ViewColumn"; | ||
import {ViewEntity} from "../../../../../src/decorator/entity-view/ViewEntity"; | ||
import {Album} from "./Album"; | ||
import {Photo} from "./Photo"; | ||
|
||
export const uppercase: ValueTransformer = { | ||
to: (entityValue: string) => {}, | ||
from: (databaseValue: string) => databaseValue.toLocaleUpperCase() | ||
}; | ||
|
||
export const lowercase: ValueTransformer = { | ||
to: (entityValue: string) => {}, | ||
from: (databaseValue: string) => databaseValue.toLocaleLowerCase() | ||
} | ||
|
||
export const removeWhitespace: ValueTransformer = { | ||
to: (entityValue: string) => {}, | ||
from: (databaseValue: string) => databaseValue.replace(/\s/g, '') | ||
} | ||
@ViewEntity({ | ||
expression: (connection: Connection) => connection.createQueryBuilder() | ||
.select("photo.id", "id") | ||
.addSelect("photo.name", "name") | ||
.addSelect("photo.albumId", "albumId") | ||
.addSelect("album.name", "albumName") | ||
.from(Photo, "photo") | ||
.leftJoin(Album, "album", "album.id = photo.albumId") | ||
.where("album.name = 'Boeing photos'") | ||
}) | ||
export class PhotoAlbum { | ||
@ViewColumn() | ||
id: number; | ||
|
||
@ViewColumn({transformer: [lowercase, removeWhitespace]}) | ||
name: string; | ||
|
||
@ViewColumn({transformer: uppercase}) | ||
albumName: string; | ||
|
||
@ViewColumn({ name: "albumId" }) | ||
photoAlbumId: number; | ||
} |
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
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
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