Get a Quote Right Now

Edit Template

 Typeorm:Simple-Json column type

 simple-json column type

There is a special column type called simple-json which can store any values which can be stored in database via JSON.stringify. Very useful when you do not have json type in your database and you want to store and load object without any hassle. For example:

@Entity()
export class User {
    @PrimaryGeneratedColumn()
    id: number

    @Column("simple-json")
    profile: { name: string; nickname: string }
}
const user = new User()
user.profile = { name: "John", nickname: "Malkovich" }

Will be stored in a single database column as {"name":"John","nickname":"Malkovich"} value. When you’ll load data from the database, you will have your object/array/primitive back via JSON.parse

Share

Leave a Reply

Your email address will not be published. Required fields are marked *