How to Use Code Generators to Create an App in Phoenix

From ElixirBlocks
Jump to: navigation, search

This page is in progress


Create Context

To create Table Data, Schema and Model information you can use this code. The example below creates the database table and the Elixir/Ecto functions needed to interact with it. This code does not create any HTML, Route or Controller data.


mix phx.gen.context Items Item items name:string



According to the official docs: Generates a context with functions around an Ecto schema.

mix phx.gen.context Accounts User users name:string age:integer

The first argument is the context module followed by the schema module and its plural name (used as the schema table name).

The context is an Elixir module that serves as an API boundary for the given resource. A context often holds many related resources. Therefore, if the context already exists, it will be augmented with functions for the given resource.