How to insert JSONB values in Postgres database #166
Replies: 4 comments
-
Can't you do the conversion prior to using it in the entity? Not sure how Dapper handles this type. |
Beta Was this translation helpful? Give feedback.
-
Hi, Dapper has a mechanism to handle it through SqlMapper.AddTypeHandler(). FastCrud however will consider it a Text field. Even if I convert it beforehand, I still need to have the serialized value converted to the proper column type e.g. '['serialized'::jsonb It would be nice to be able to achieve a similar approach with FastCRUD by leveraging OrmConfiguration. At the moment my List Property is not even registered with the entity, which means I can't query for it. I ended up using something like this.
And I created a sql statement
I have the proper type handler defined in Dapper, and so I can do a basic query.
The configuration that FastCRUD exposes should be extended to support custom types, I just don't have enough knoweldge of the code base to handle this. |
Beta Was this translation helpful? Give feedback.
-
I struggled with this issue as well when trying to use PostgreSQL’s date-range capabilities. The trick I discovered was to implement Range<T> and DateRange SqlMapper handlers as you would for standard Dapper use and then manually register the members using the SetProperty method mentioned above. This approach seems to force the custom fuel types to register. Hopefully this saves someone else the time I spent deciphering this issue. |
Beta Was this translation helpful? Give feedback.
-
Hello! First time Dapper & Dapper.FastCrud user. I will need to use PostgreSQL First, postgres has two json database type
With these types defined, a
From here all that was left is to define the dto and it's jsonb column
Finally, I needed to register my handler for the record. Since I was using Fluent mapping, I did the following when defining the
This helped. I still need to explore the source generators tip. NOTE: This code has been truncated and freehanded. Please excuse any compiler issues.
Dapper |
Beta Was this translation helpful? Give feedback.
-
Hi,
I would like to leverage FastCRUD to also insert columns that have JSONB types in Postgres.
I've been scanning the source code, but I don't see an example of this. None of the issues seem to match either.
Is there a way to have a complex type automatically converted to a json value for insert/update, and vice-versa for retrieval?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions