Working with Ecto: Difference between revisions

From ElixirBlocks
Jump to: navigation, search
No edit summary
No edit summary
Line 19: Line 19:


==IEX Commands==
==IEX Commands==
===Get All ===


<source>
<source>
App.TestBeds.TestBed |> App.Repo.all  
App.TestBeds.TestBed |> App.Repo.all  
</source>
=== Insert ===
<source>
%App.TestBeds.TestBed{name: "some-item-name"} |> App.Repo.insert
</source>
</source>

Revision as of 07:41, 24 September 2023

This page is in progress


https://brooklinmyers.medium.com/ecto-with-phoenix-in-4-minutes-9b7c447055c6


Update all tables that contain a field with a chosen value

   def reset_testbeds do
    items = from t in TestBed, where: t.status == "Taken"
    Repo.update_all(items, set: [status: "Available", developer: "None"])
    |> broadcast_change([:testbed, :reset])
  end

IEX Commands

Get All

App.TestBeds.TestBed |> App.Repo.all


Insert

%App.TestBeds.TestBed{name: "some-item-name"} |> App.Repo.insert