-
-
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
Added simple-enum column type #3700
Conversation
@@ -288,6 +290,10 @@ export abstract class AbstractSqliteDriver implements Driver { | |||
|
|||
} else if (columnMetadata.type === "simple-json") { | |||
value = DateUtils.stringToSimpleJson(value); | |||
|
|||
} else if ( columnMetadata.type === "simple-enum" ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since sqlite supports enum
now, it should have enum
type as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, don't forget to list new types in the docs (website)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or using CHECK constraint in sqlite can't be called enum
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot find native enum support on the SQLite website: https://www.sqlite.org/datatype3.html.
I would say it makes sense to have enum
for native enum types, and simple-enum
for the emulated enum type. That way it will be more clear when you are using a derived/emulated type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is currently no section on either enums or simple-
types on the website. Do you want me to create one in a pull request?
Also, are you aware that the website certificate is invalid when accessing it from https://typeorm.io/?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, are you aware that the website certificate is invalid when accessing it from https://typeorm.io/?
yes =(
There is currently no section on either enums or
simple-
types on the website. Do you want me to create one in a pull request?
yes feel free please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 other simple-
types are now mentioned, but simple-enum
is not:
https://typeorm.io/entities#simple-array-column-type
#10077
Great work! Asking @AlexMesser for review |
Thank you so much! |
@borremosch thanks! :) |
Found a bug in this PR, that prevents me from using a protected word like "from" as the column name. For example: export enum FromType {
NO_REPLY = 'no-reply',
RANDOM = 'random',
}
@Entity('broadcast')
class BroadcastEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({
type: 'simple-enum',
enum: FromType,
nullable: false,
})
from: FromType;
} Here's the error:
As you can see, the generated column: It should look like this: (The column name must be wrapped in double-quotes.) This was in sqlite, if that matters. |
Note that we use `simple-enum` instead of `enum` because sqlite doesn't support enum, but this PR allows a workaround by adding a `simple-enum` type. typeorm/typeorm#3700
Note that we use `simple-enum` instead of `enum` because sqlite doesn't support enum, but this PR allows a workaround by adding a `simple-enum` type. typeorm/typeorm#3700
When using simple-enum and using 'synchronise' in the connection options i get a continuous "column has changed errors" (i.e. it keeps ALTER table).
Removing it naturally removes the CHECK IN feature but there is some error in detecting if a column schema is the same and should be altered. This is in TypeORM 0.2.25 and SQLite 3 adapter 4.2.0. |
I have added the
simple-enum
column type discussed in #1414. It works like this:ENUM
type is usedCHECK()
constraint is used, like so:ENUM
type, I believesimple-enum
should be based on it. I have not addedsimple-enum
for Oracle.