Skip to content
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

feat(postgres): add support for native enums #4296

Merged
merged 2 commits into from
May 1, 2023
Merged

feat(postgres): add support for native enums #4296

merged 2 commits into from
May 1, 2023

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented May 1, 2023

By default, the PostgreSQL driver, represents enums as a text columns with check constraints. Since v6, you can opt-in for a native enums by setting the nativeEnumName option.

@Entity()
export class User {

  @Enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}

Closes #2764

@codecov
Copy link

codecov bot commented May 1, 2023

Codecov Report

Patch coverage: 98.96% and project coverage change: -0.01 ⚠️

Comparison is base (c2077db) 99.47% compared to head (0ac757c) 99.46%.

Additional details and impacted files
@@            Coverage Diff             @@
##               v6    #4296      +/-   ##
==========================================
- Coverage   99.47%   99.46%   -0.01%     
==========================================
  Files         219      219              
  Lines       14441    14515      +74     
  Branches     3314     3332      +18     
==========================================
+ Hits        14365    14438      +73     
- Misses         75       76       +1     
  Partials        1        1              
Impacted Files Coverage Δ
packages/core/src/decorators/Enum.ts 100.00% <ø> (ø)
packages/core/src/typings.ts 100.00% <ø> (ø)
packages/postgresql/src/PostgreSqlSchemaHelper.ts 99.47% <96.66%> (-0.53%) ⬇️
packages/core/src/metadata/EntitySchema.ts 100.00% <100.00%> (ø)
packages/core/src/metadata/MetadataDiscovery.ts 99.30% <100.00%> (+<0.01%) ⬆️
packages/core/src/platforms/Platform.ts 99.56% <100.00%> (+<0.01%) ⬆️
packages/knex/src/schema/DatabaseSchema.ts 100.00% <100.00%> (ø)
packages/knex/src/schema/DatabaseTable.ts 100.00% <100.00%> (ø)
packages/knex/src/schema/SchemaHelper.ts 100.00% <100.00%> (ø)
packages/knex/src/schema/SqlSchemaGenerator.ts 100.00% <100.00%> (ø)
... and 2 more

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@B4nan B4nan merged commit 0b4a262 into v6 May 1, 2023
@B4nan B4nan deleted the native-pg-enum branch May 1, 2023 14:37
jsprw pushed a commit to jsprw/mikro-orm-full-text-operators that referenced this pull request May 7, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes mikro-orm#2764
B4nan added a commit that referenced this pull request May 14, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
B4nan added a commit that referenced this pull request May 14, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
B4nan added a commit that referenced this pull request May 24, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
B4nan added a commit that referenced this pull request May 26, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
B4nan added a commit that referenced this pull request Jun 11, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
B4nan added a commit that referenced this pull request Sep 10, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
B4nan added a commit that referenced this pull request Sep 20, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
B4nan added a commit that referenced this pull request Sep 24, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
B4nan added a commit that referenced this pull request Sep 30, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
@B4nan B4nan mentioned this pull request Sep 30, 2023
22 tasks
B4nan added a commit that referenced this pull request Oct 2, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
B4nan added a commit that referenced this pull request Oct 17, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
B4nan added a commit that referenced this pull request Oct 21, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
B4nan added a commit that referenced this pull request Oct 25, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
B4nan added a commit that referenced this pull request Nov 2, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
B4nan added a commit that referenced this pull request Nov 5, 2023
By default, the PostgreSQL driver, represents enums as a text columns
with check constraints. Since v6, you can opt-in for a native enums by
setting the `nativeEnumName` option.

```ts
@entity()
export class User {

  @enum({ items: () => UserRole, nativeEnumName: 'user_role' })
  role!: UserRole;

}

export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
}
```

Closes #2764
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant