Schemas

Our ElixirDrip project allows users to safely store their media, and eventually share it with other users. Therefore, we need to have a way to represent users and media as database tables.

To help developers with this, Ecto has the schema construct. Its purpose is to establish a mapping between any information stored in the database and its representation in Elixir data structures.

Let's define the schema to represent the users' media:

$ cat apps/elixir_drip/lib/elixir_drip/storage/media.exdefmodule ElixirDrip.Storage.Media do  use Ecto.Schema  schema "storage_media" do    field :user_id, :id    field :file_name, :string    field :full_path, :string    field :file_size, :integer    field :metadata, :map, default: %{} field :encryption_key, :string ...

Get Mastering Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.