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

Npgsql: Use EnableDynamicJson to unlock better container type mappings #777

Merged
merged 4 commits into from
Dec 20, 2024

Conversation

amotl
Copy link
Member

@amotl amotl commented Dec 19, 2024

About

This patch resolves a few FIXME admonitions introduced by a recent patch that started to validate all of CrateDB's data types with Npgsql.

Details

Vanilla Npgsql provides good enough support to handle CrateDB's ARRAY and OBJECT types better than just plain strings. This patch demonstrates type mappings using three different variants:

  • Native .NET System.Collections.Generic.List and System.Collections.Generic.Dictionary types.
  • Native .NET System.Text.Json.JsonDocument type. 1 Thanks, @simonprickett.
  • Custom .NET POCO types.

What's Inside

  • Use NpgsqlDbType.Json explicitly where applicable, for example when communicating parameters using AddWithValue().
  • Use EnableDynamicJson() on the NpgsqlDataSourceBuilder, for POCO and Dictionary mappings that didn't work before.

What's Next

Include relevant information into a dedicated documentation page, in order to educate readers properly in the spirit of "seeing is believing".

Footnotes

  1. Currently works with OBJECT for me, but not ARRAY.

@amotl amotl force-pushed the npgsql-type-mapping branch 2 times, most recently from 5bd679a to e88bbc5 Compare December 19, 2024 22:06
@amotl amotl force-pushed the npgsql-type-mapping branch from e88bbc5 to 5fdd7ff Compare December 19, 2024 23:33
Vanilla Npgsql provides good enough support to handle CrateDB's ARRAY
and OBJECT types better than just plain strings. This patch demonstrates
type mappings to native .NET `List` and `Dictionary` types, as well as
type mappings to custom .NET POCO types.
CrateDB's OBJECT data type can also be communicated using .NET's native
`System.Text.Json.JsonDocument` type.
@amotl amotl force-pushed the npgsql-type-mapping branch from 5fdd7ff to 970c259 Compare December 19, 2024 23:34
@amotl amotl requested review from simonprickett and kneth December 19, 2024 23:40
@amotl amotl marked this pull request as ready for review December 19, 2024 23:40
by-language/csharp-npgsql/README.rst Show resolved Hide resolved
@amotl amotl merged commit 999bc20 into main Dec 20, 2024
4 checks passed
@amotl amotl deleted the npgsql-type-mapping branch December 20, 2024 09:41
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.

2 participants