3 ms·
The trick to Ecto is that it serves as a separation between your data storage, and your data representation in your code. Basically, there're 3 parts. The firs
by OkayPhysicist 6y ago
The trick to Ecto is that it serves as a separation between your data storage, and your data representation in your code. Basically, there're 3 parts.
The first part is your schema. It defines an Elixir struct that is your domain model of your data.
The second idea/part is the concept of a changeset. It represents a change you'd like to make to the data store, but haven't yet. These are composable, so you can bundle a bunch of changes into a single, atomic unit, which you then send to your repo. If any part fails, then the whole thing fails, no changes are made to the persisted data.
The last thing is migrations, which strictly speaking are optional, but a huge convience. They define how you'd like your database to be structured. The cool thing about them is that they define rollback operations automatically.
Once Ecto "clicks", it really becomes a strong selling point to the language as a whole. It makes working with persisted data super easy.