Deleting Data
Similar to updating, we must first fetch a record from the database and then call Taskers.Repo.delete
to delete that record:
task = Taskers.Repo.get(Taskers.Tasks, 1) | |
Taskers.Repo.delete(task) | |
#=> {:ok, %Taskers.Tasks{__meta__: #Ecto.Schema.Metadata<:deleted, "tasks">, id: 1, title: "Hello Reader"}} |
Similar to insert and update, delete returns a tuple. If the deletion succeeds, then the first element in the tuple will be :ok
, but if it fails then it will be an :error
.
This marks the end of our 7 part Elixir Ecto tutorial, if you’ve missed some parts, feel free to go through My profile posts and you can find a detailed scope of the topic.
Top comments (0)