![]() If you are using version 1.3 of the Phoenix framework then make sure you use mix phx. Let’s try to create a new table in our database to keep the information about rooms.Įcto provides us migration generators, which we can use to describe the structure of the table and apply those changes in a database. Query - Wrapper in Elixir around SQL queries.Changeset - Provides a way to cast attributes value into correct types, add validation rules and constraints.It converts table’s columns into Struct items. Schema - Think of that as a mapping between a database table and its columns with the Elixir struct.It can provide access to different data storages such as databases or in-memory storages. The Repo hides implementation details from models. Models hide implementation details from the rest of components. Repo - the repository of data storage.Or does it?Īnyway, Ecto is a library and domain-specific language to interact with databases. Probably what is why Ecto cannot be considered as ORM. We know, Elixir is not an Object-Oriented Programming language. Object-relational mapping (ORM, O/RM, and O/R mapping tool) in computer science is a programming technique for converting data between incompatible type systems using object-oriented programming languages. If we take a look at ORM’s description from Wikipedia page: If you are familiar with other frameworks you probably know about ORM (Object-relational Mapping and might think: “Ah. ![]() We are communicating with it through an additional layer called Ecto. In the Phoenix framework, we are not working database directly. As you may know from the first article of these series, We will use PostgreSQL for that application. Nowadays almost every application has a persistent storage. Also, there is no way to manage rooms by users of our application. Every time we want to update the list of the rooms we need to update the code. We have the rooms list in our application. We will get to that question soon as well. You may also notice why does that model is called Conversation instead of Room. Yes, that data is hardcoded at the moment, but we are going to change it soon. Our controller and view use that data to render a list of the rooms on the page. We have created a model which provides us data about rooms. Let’s quickly sum up what we did till now. We have used a comprehension here to iterate through a list of the rooms and render the element for each room.Īnd now our page looks as it was at the beginning.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |