-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Column default value as function #150
Comments
@PrimaryColumn({
name: "id",
type: "bigint",
default: "new_id()"
})
Id: number; Doesnt it work? |
@pleerock not work
|
mmm probably because of escaping... Probably we can add another option like |
@pleerock mb it is dirty, but we can check default value : function or not (regexp or another way). |
can we cover all cases with such regexp? I would like to hear something better then |
I have an idea, but maybe it's too much complex. Wrap the values that are sent to the database in some class, like |
5000 option and parameters makes the decorators code big and gross. I would preffer simple solutions like I don't know how about TypeORM v0.0.6 but the older version required quotes in string for default values: @Column("string", { default: "'normal'" }) so we could also make this part of code more inteligent - if field is string, wrap argument in quotes in sql, if number no, etc. My proposition are twos:
@PrimaryColumn({ default: () => "new_id()" }) it could be even
It could also be an alternative to |
Thank you guys for the feedback.
@eduardoweiland This is really cool idea, much better then @19majkel94 I would like to prevent extra rules like "!" or "&" which aren't intuitive. But you bring a valueable point, what if value is lets say I think better if we won't do escaping at all, and those who want to use strings should put single quotes. It will solve all the problems and its intuitive enought (but still we need point this in docs). |
Ive made a decision to use @19majkel94 suggested solution to use @Column({ default: "Umed" })
name: string; generates @Column({ default: 1 })
count: number; generates @Column({ default: true })
isSomething: boolean; generates @Column({ default: () => "pow(5)" })
count: number; generates This fix released in |
I have column Id:
In database i have function: new_id() for generate ids. How i can implement this query?
id bigint NOT NULL DEFAULT new_id()
The text was updated successfully, but these errors were encountered: