You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Public API for managing type handling/mapping #1475
The type handler API is currently purely internal in Npgsql - it's not possible for users to provide their own handlers, either for custom types not yet supported by Npgsql or to override the default behavior.
Once the type handler API is deemed stable enough, provide an API to allow users to do their own type mapping/handling.
In my specific case, we're using a fork Agensgraph that requires the addition of Vertex, Edge, GraphId and Path types. Since this is not a very popular fork, it does not make much sense to include these type handlers directly in the core NpgSql repository. Falling back to the text-based protocol is not an option for us.
Another scenario: some users want to do their own timezone conversion (e.g. #1469 (comment)), this could be done by overriding the default date/time handlers.
In a similar way, this would allow users to get Nodatime types (#546).
Possible complication to consider - the EF Core provider dynamically loads Npgsql's type mappings for its own type mapping... Think about the implications.
Another nice scenario - json/jsonb handlers which add the possibility to read/write directly to objects, performing serialization/deserialization with NewtonSoft.JSON. This adds another layer of complexity, since a type handler currently can't support reading an arbitrary type - it must specify which types are supported by implementing ISimpleTypeHandler<T> etc. But this would be really nice.
For anyone interested, until there's some proper documentation take a look at the Json.NET plugin (src/Npgsql.Json.NET). It shows what a basic type handler can do. A Nodatime plugin is also in the works.
I'd love to get feedback on the API etc. There may definitely be some things - I've tried not to expose too many internal APIs, at least not until we know they are needed.
And one last word of warning :) This is a very new extensibility API, and although I spent some time on making sure it's good it may definitely change a little as shortcomings and extra needs are discovered. If you actually develop an external plugin be prepared that although public, this API may definitely change.
Activity
johnberzy-bazinga commentedon May 19, 2017
Following up from the issue #1550 :
In my specific case, we're using a fork Agensgraph that requires the addition of Vertex, Edge, GraphId and Path types. Since this is not a very popular fork, it does not make much sense to include these type handlers directly in the core NpgSql repository. Falling back to the text-based protocol is not an option for us.
Thanks,
John
roji commentedon May 23, 2017
Another scenario: some users want to do their own timezone conversion (e.g. #1469 (comment)), this could be done by overriding the default date/time handlers.
In a similar way, this would allow users to get Nodatime types (#546).
roji commentedon May 23, 2017
Possible complication to consider - the EF Core provider dynamically loads Npgsql's type mappings for its own type mapping... Think about the implications.
roji commentedon Jun 16, 2017
Another nice scenario - json/jsonb handlers which add the possibility to read/write directly to objects, performing serialization/deserialization with NewtonSoft.JSON. This adds another layer of complexity, since a type handler currently can't support reading an arbitrary type - it must specify which types are supported by implementing
ISimpleTypeHandler<T>etc. But this would be really nice.roji commentedon Jul 3, 2017
This was done in 4a503c7 (and some in c3dd084).
Need to document.
johnberzy-bazinga commentedon Jul 3, 2017
This looks great! Thanks @roji!
roji commentedon Jul 3, 2017
For anyone interested, until there's some proper documentation take a look at the Json.NET plugin (src/Npgsql.Json.NET). It shows what a basic type handler can do. A Nodatime plugin is also in the works.
I'd love to get feedback on the API etc. There may definitely be some things - I've tried not to expose too many internal APIs, at least not until we know they are needed.
[-]Open up type handling/mapping[/-][+]Public API for managing type handling/mapping[/+]roji commentedon Jul 3, 2017
And one last word of warning :) This is a very new extensibility API, and although I spent some time on making sure it's good it may definitely change a little as shortcomings and extra needs are discovered. If you actually develop an external plugin be prepared that although public, this API may definitely change.