The good thing about this approach is that we'll have our context modules talk to the Ecto schema modules, and Phoenix controllers will only talk to domain functions in the appropriate context modules, which will help us keep code clean and organized.Įach context will hold one or more Ecto schemas serving as data mappers for our tables - based on our functional requirements, here's an outline of what structure we'll use:Īn Auth context, containing the User schema. A context often holds many related resources. >The context is an Elixir module that serves as an API boundary for the given resource. Phoenix promotes the concept of contexts to organize your business logic code and encapsulate the data access layer. We would also like to have a Slack-like emoji reaction system, in which any conversation member can react to a message with one or more defined emojis, all of which have a name and a Unicode representation. Each message is part of a conversation, which is associated with two or more users, with a message always having a specified sender.Īs in most modern instant messaging apps, we want a "Message Seen" feature that tracks which conversation members have seen a message, in which every information about who's seen a message has a specific timestamp. We want to store users communicating messages between them. create Analyze requirements, define contexts and Ecto schemasīefore we proceed to add LiveView to our project, let's design the data model driving the app's intended business logic. Now, let Ecto, which is Phoenix's default data access library, create the database in your local DB server for you: mix ecto. This is a good moment to make an initial commit, by the way, if you'd like to. sample appended to their names if you'd like to keep things simple for those who clone your repository. You can make copies of those files (with your credentials blanked out), intended to be tracked in source control, with. Put import_config "" and import_config "" at the end of dev.exs and test.exs, respectively. Show_sensitive_data_on_connection_error: true, So, let's create and files in the same folder, with database config copied from the original ones - obviously, if you're using different usernames, or would like to change other options, just do so: # use Mix.ConfigĬonfig :curious_messenger, CuriousMessenger.Repo, It is a good practice to keep separate and files just as it's done by default with, and ignore them in source control sample files can be provided for easier bootstrapping. Database credentials shouldn't be shared in repositories - for production it would be a security concern, while for dev and test it's just annoying to your collaborators because everyone's got a slightly different setup. Phoenix creates a basic database configuration for all environments in config/dev.exs, config/test.exs and config/prod.exs. We won't stray from Phoenix's default setting and we're going to use PostgreSQL as our database for storing all of the app's data, including users, conversations, messages, and all metadata - have a look at PostgreSQL Wiki for guides on installing it. if you'd like to track changes with Git, which is always highly recommended. Now create Phoenix's basic project structure using the installed script: mix phx. Needless to say, Elixir and Erlang need to be installed, as well as NodeJS - we recommend the asdf-vm extensible version manager as a tool that can manage all of them. If these are your very first steps in Phoenix Framework, please install the framework's bootstrapping scripts - Phoenix's Hex documentation will be helpful for you. To learn even more about how we'll build our Messenger app and get deeper into Phoenix LiveView, subscribe to our newsletter and await further episodes of the series! Initial steps: install Phoenix, create the project
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |