Wrapping Up: Use Schemas Without Tables

Review what we have learned about the use of schemas without tables.

We'll cover the following

Schemas in Ecto require a manual setup to map them to database tables. In exchange for that effort, we get data structures that are flexible and able to work with our application’s specific needs.

With Ecto, it’s possible to break out of the constraints of having our data structures locked to our database tables. We can design our structs around the needs of our application code rather than our database and still not lose any of the conveniences that changesets provide.

In this chapter, we learned about one use case for table-less schemas, but there are other use cases as well. In “Using Changesets Without Schemas”, we used the validations from the Changeset module to help validate a search form that we weren’t persisting to a database. In that example, we used a map to define the data structure we wanted to validate, but we could have used a table-less schema. That might have been a better choice if we wanted to take advantage of some of the other supporting functions that schemas provide. The idea is the same in either case—Ecto’s data manipulation tools are available to us even when not working with a relational database.

Get hands-on with 1200+ tech skills courses.