Skip to content

Set @Column() default db type for string properties to 'text' instead of 'varchar' #7979

Closed

Description

@MWhite-22

Documentation Issue

Set @column() default db type for string properties to 'text' instead of 'varchar'

What was unclear or otherwise insufficient?

Is is possible to change the TypeOrm default db types for string properties? The documentation makes no mention but I assume each driver has its own definitions of what primitive types match what db types.

Activity

  1. amittal-quot commented on Jul 30, 2021

    @amittal-quot

    you can use @column({type:"text"})

  2. MWhite-22 commented on Jul 30, 2021

    @MWhite-22
    Author

    I know I can for individual columns but I have 45 tables, some with 20+ columns.

    I want to change the typeorm setting that makes decorating a string property with a normal @column() decorator default to ‘text’

  3. blazmrak commented on Aug 1, 2021

    @blazmrak

    @Xzas22 You can have that done in an hour, maybe two and it is a one time job.

    If you want you can modify the driver locally here and then use it, but you will have to maintain it. Keep in mind that there is no guarantee that something else won't break because of this.

  4. pleerock commented on Aug 2, 2021

    @pleerock
    Member

    If you asking about changing default behavior - no, we can't do that because using text is limiting your strings in a number of ways and you'll have different performance problems with this approach.

    If you asking about providing a special configuration for such purpose - then answer is no, we can't do that because it is too specific request.

    @blazmrak provided a good solution for your request. You can also create your "own column decorator" that simply calls default "Column" decorator, but with type set to text.

  5. AlissonRS commented on Jul 22, 2022

    @AlissonRS

    @pleerock I'm afraid they were not asking to change it in the library itself, but rather an option for devs to configure what should be the default db type for string (or even number?) in their own project.

    I agree that text has limitations, but so does varchar. In my project I'd like all string columns to be nvarchar by default as it avoids a lot of pain when dealing with unicode characters, please check the most upvoted answer here for the rationale: https://stackoverflow.com/questions/144283/what-is-the-difference-between-varchar-and-nvarchar

    Would it be possible to at least provide an option for us to override that? I'm currently using custom decorators as you suggested, but I wanted new devs joining the team to have a smoother onboarding being able to use TypeORM as it is, without having to think about custom decorators, and coming from Entity Framework for C# I really miss this feature.

    Thanks and I appreciate this great library!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions