-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Support enum for DB who don't support it #1414
Comments
I'm a big fan of making ORM-Systems really universal or at least as much universal as it can get. |
@mhombach sorry to disappoint you, but Im biggest anti-fun of universal ORM-systems, simply because:
But this particular feature request we can implement, because it does not restrict / limit us in anything, its just an addition. |
I once wrote a full app using an orm(not typeorm) using linux + mysql for in-house usage, then my boss came and told me I have to deploy same app to one of our clients. The catch was it was supposed to run on windows with mssql. Obviously it took me some time to get the job done and I would have greatly appreciated if the orm I was using would allow me to abstract things more. In any case since there is already simple-array and simple-json, why not add simple-enum? Also an option with "useNativeTypeIfAvailable" would be even better. |
This issue is opened for the community. Feel free to implement |
My 5 cents... @antoine-pous I came into this issue a couple of day before looking for the same kind of functionality. The outcome of it did not look well so i tried to solve it working around. I am working with // CostType.ts
export enum CostType {
TOTAL = 'total',
TAX_TOTAL = 'taxTotal',
GRANT_TOTAL = 'grantTotal'
}
// CostEntryOrmModel.ts
@Entity('costEntry')
export class CostEntryOrmModel {
@PrimaryGeneratedColumn()
identifier: number;
// note here how the type is specified to be the type of value in enum
@Column({type: 'varchar'})
id: CostType;
// .....
} Would this work for you? Can you give it a try and report back your feedback? If I find time this week I can make a pull request with some tests to make a PoC Cheers |
@borremosch could you please provide an example for this implementation? I am mostly interested for the MSSQL.
|
@maxxims you'll have to add the enum type to the column decorator as well, just like with a regular enum:
Hope this solves it |
Should this issue be closed as #3700 was already merged? |
Currently SQLite doesn't have
ENUM
type, but TypeORM can use it's own validator before inserting a value into the DB and emit an error when the value is not in the enum.The text was updated successfully, but these errors were encountered: