October 2019
Intermediate to advanced
358 pages
8h 22m
English
With our database ready, we can begin to persist our Accounts.User structs. Let’s hop into an IEx shell and create the users that we previously hardcoded in our Accounts context.
Spin up your console with iex -S mix, and insert some data:
| | iex> alias Rumbl.Repo |
| | iex> alias Rumbl.Accounts.User |
| | |
| | iex> Repo.insert(%User{ |
| | ...> name: "José", username: "josevalim" |
| | ...> }) |
| | [debug] QUERY OK db=5.0ms |
| | INSERT INTO "users" ("name","username","inserted_at", |
| | ... |
| | {:ok, |
| | %Rumbl.Accounts.User{__meta__: #Ecto.Schema.Metadata<:loaded, "users">, |
| | id: 1, |
| | inserted_at: ~N[2017-10-25 19:13:28.878179], |
| | name: "José", |
| | updated_at: ~N[2017-10-25 19:13:28.879737], |
| | username: "josevalim"}} |
| | |
| | iex> Repo.insert(%User{ ... |
Read now
Unlock full access