Show Menu

Elixir Ecto 2.2 Cheat Sheet (DRAFT) by

Elixir Ecto cheat sheet

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Mix Tasks

Generate Repo: mix ecto.c­reate
New migration: mix ecto.g­en.m­ig­ration create­_posts
Migrate: mix ecto.m­igrate . Default all pending, options --step n, --to versio­n_n­umber, --all
Rollback: mix ecto.r­ollback . Default latest, options --step n, --to versio­n_n­umber, --all
Drop Repo (and drop everyt­hing) : mix ecto.drop
Status: mix ecto.m­igr­ations
Multiples DB ?: mix ecto.g­en.repo . Dont forget to configure it in config.exs

Create Table (Phoenix)

mix­n.s­chema ModelName tablename attributes
ModelName: should be camel cased
tablename: should be lower cased, plural
attribute: name:type[:modifier]
types: :id, :interger, :float, :boolean, :string, :binary, :decimal, :utc_d­atetime, :array, :map, :references
references: need a table name: user_i­d:r­efe­ren­ces­:users
unicity: userna­me:­str­ing­:uniq
array: emails­:ar­ray­:string