DEV Community

Cover image for Getting Started on Elixir and Ecto Part 7
Kenzy Limon
Kenzy Limon

Posted on

1

Getting Started on Elixir and Ecto Part 7

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"}}
view raw delete.ex hosted with ❤ by GitHub

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)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay