...
/Adding Custom Types Without the Built-In Types
Adding Custom Types Without the Built-In Types
Learn how to add custom types without using the built-in types.
So far, the custom types we’ve created have been built on the types already included in Ecto. When we add a layer on top of a built-in type, we can have richer data types in our Elixir code than we’d have just using the standard database types.
Write the driver extension
However, if we want to work with a data type not currently supported in Ecto, we’ll need to go into a little more detail and write our driver extension.
To better understand how that might work, let’s take a closer look at how data moves from our Elixir code to the database and back, as shown in this figure.
Database and drivers
We start at the database, where the raw data is stored. Next, we have the driver, which handles converting values from the database into Elixir. Drivers are database-specific—there’s an Elixir driver for Postgres, another for MySQL, and so on.
Adapters
Then we get into Ecto itself. Ecto sits on top of the database drivers and implements adapters for each of the database drivers. The adapters create a uniform ...