forked from typeorm/typeorm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can't save a ES6 Map or Set variable as a string or blob type in the …
…column
- Loading branch information
Showing
3 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
test/functional/columns/value-transformer/entity/PhoneBook.ts
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,31 @@ | ||
import {Entity} from "../../../../../src/decorator/entity/Entity"; | ||
import {Column} from "../../../../../src/decorator/columns/Column"; | ||
import {ValueTransformer} from "../../../../../src/decorator/options/ValueTransformer"; | ||
import {PrimaryGeneratedColumn} from "../../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
|
||
|
||
class PhonesTransformer implements ValueTransformer { | ||
|
||
to (value: Map<string, number>): string { | ||
return JSON.stringify([...value]); | ||
} | ||
|
||
from (value: string): Map<string, number> { | ||
return new Map(JSON.parse(value)); | ||
} | ||
|
||
} | ||
|
||
@Entity() | ||
export class PhoneBook { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
name: string; | ||
|
||
@Column({ type: String, transformer: new PhonesTransformer() }) | ||
phones: Map<string, 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