Skip to content

first class support for custom (un)marshallers #289

Description

@maxcan

So i want to use momentjs instead of Date for my records and this is how I was able to get it typeorm to work:

    @BeforeInsert() _setDt() {this.date = this.date.toDate() as any}
    @BeforeUpdate() _setDt1() {this.date = this.date.toDate() as any}
    @AfterLoad() _setDt2() {this.date = moment(this.date)}
    @Column({ type: "date", nullable: false }) date: moment.Moment

it would be great if there was a first class column option for setting up our own marshalling and unmarshalling so we didn't have to break types with as any

@Column({ 
    type: "date", 
    nullable: false, 
    marshaller: {
        toDb: d => d.toDate(), 
        fromDb: d => moment(d)
    }
}) date: moment.Moment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions