Implementing and querying Ecto.Type

I’m currently working on an application which has a table in the associated postgresql database with a JSONB field. That field, in the ecto schema, is represented with a struct from a map type very similarly to the URI in the following example from the ecto docs.

https://hexdocs.pm/ecto/Ecto.Type.html

I’ve tried, without success, to write queries where I select: on certain data within that field. Thus far I’ve tried using the ecto query map/2, struct/2 as well as a fragment with raw SQL using postgres’ syntax for fetching data within JSONB fields.

If I temporarily swap the type of the field on the ecto schema to a :map instead of the struct, the queries work just fine, however it is not an option in my particular case.

My question more broadly is just if it is indeed possible to query data from these custom struct fields (with map types) in ecto? If so, any help would be appreciated.

2 Likes