MySqlConnector icon indicating copy to clipboard operation
MySqlConnector copied to clipboard

Type-mapping plugin API

Open jack-pappas opened this issue 4 years ago • 1 comments

npgsql supports a "type-mapping plugin" API which can be used to override or extend the library's built-in mappings between postgresql data types and CLR types. For example, the Npgsql.NodaTime plugin adds support to allow postgresql date/time types to be decoded directly into instances of the corresponding NodaTime types: https://www.npgsql.org/doc/types/nodatime.html

This feature is especially useful for preserving correctness / intent of the original data when there's no equivalent CLR type. To use the NodaTime example again, MySqlConnector will currently translate a mysql Date column into the .NET DateTime type, but that's not quite correct: a DateTime represents an instant in time, but a Date represents a granularity of one day so is more interval-like (which is represented by the NodaTime LocalDate struct).

A type-mapping plugin API in MySqlConnector would allow some of the edge cases or specialized column types to be handled better (or customized, if needed) without adding more complexity or library dependencies to the core MySqlConnector library.

jack-pappas avatar Apr 01 '20 19:04 jack-pappas

Related cases (that could probably all be solved with a well-designed plugin API):

  • Custom data types - https://github.com/mysql-net/MySqlConnector/issues/123
  • Spatial data types: https://github.com/mysql-net/MySqlConnector/issues/70
  • Utf8String - https://github.com/mysql-net/MySqlConnector/issues/618

bgrainger avatar Apr 01 '20 20:04 bgrainger