Introduction to Custom Types in Ecto

Learn about using custom types when there's a need to use a data type not directly supported by Ecto.

We'll cover the following

In this chapter, we’ll learn the data types Ecto provides to create schemas. Ecto uses these data types to translate values expressed in Elixir code into values that a database can store. A String value in Elixir, for example, becomes a VARCHAR when stored in a MySQL table.

Ecto’s built-in data types will give us everything we need most of the time. However, there may be times when we want to use a data type not directly supported by Ecto. For these cases, Ecto provides a mechanism for defining our custom types. We can add support for storing any data type in our database by implementing the functions mentioned in this chapter.

Get hands-on with 1200+ tech skills courses.