Chapter 3Connecting Your Tables to Elixir Structs with Schemas

Functional programs have a set of data structures that form the backbone of the codebase. In the music database we’ve been developing, we’ve got things like artists, albums, tracks, etc. The Ecto.Schema module helps us map those data structures to database tables, so we can seamlessly move data back and forth between our Elixir code and the database. You create the mappings with an elegant, concise DSL, then use associations to connect related structures together.

With schemas, you’ll be able to create more streamlined operations for querying, inserting, and updating data. Schemas are quite flexible and can be used to map data from any data source (not just database tables) into ...

Get Programming Ecto now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.