With R2dbc postgresql, we can easily map java enum type with database enum type:
@Bean
public ConnectionFactory pgConnectionFactory() {
return new PostgresqlConnectionFactory(
PostgresqlConnectionConfiguration.builder()
.host("localhost")
.database("test")
.username("user")
.password("password")
.codecRegistrar(EnumCodec.builder().withEnum("status", Status.class).build())
.build()
);
}
Now I want to apply this mapping to: mariadb, mssql, oracle and so on. Do these dbmss have the same functionality?
MariaDB supports the same enum type as MySQL, which is just a fancy check constraint on a VARCHAR
column, not an actual enum type.
If you want to implement database agnostic enum types across all those dialects, I recommend you use CHECK
constraints instead of enums.
Note that hopefully, a future version of the r2dbc-postgresql driver will support enum types out of the box: https://github.com/pgjdbc/r2dbc-postgresql/issues/429
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.