Custom Ecto Type Questions

I’m currently facing a common problem that I believe is refered to as the EAV model in database modeling. Where I am going to be storing answers to questions. Those answers could be many different types, everything from booleans(Yes / No), Strings, Numbers, Dates, ect…

I had a thought, and I’m not sure if it’s even possible and or if it would be a terrible idea. Or…maybe there’s a better way to do this?

But would it be possible to write a custom ecto type using the Ecto.Type behavior that would store the answer value along side the answer datatype. So that I can use one column to store the answer and then still have types when I read it back into Elixir?

I’ve also been exploring JSONB.

ex_money is using a single column to store amount and currency. Maybe look at how it handles that.

Ahh thanks, yea it looks like they are using a custom ecto type as well:

I guess there’s a thing called composite types in Postgresql that it uses as well. Interesting…