From 38b66d1bc625ef3ebb566c22034d9318362d8911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 8 Apr 2020 13:39:19 +0200 Subject: [PATCH] Improve docs --- lib/ecto.ex | 10 ++++++++++ lib/ecto/repo.ex | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/ecto.ex b/lib/ecto.ex index b6241a0880..689259f2a3 100644 --- a/lib/ecto.ex +++ b/lib/ecto.ex @@ -637,6 +637,16 @@ defmodule Ecto do Ecto.Schema.Loader.unsafe_load(schema_or_types, data, &Ecto.Type.embedded_load(&1, &2, format)) end + @doc """ + Dumps the given struct defined by an embedded schema. + + This converts the given embedded schema to a map to be serialized + with the given format. For example: + + iex> Ecto.embedded_dump(%Post{}, :json) + %{title: "hello"} + + """ @spec embedded_dump(Ecto.Schema.t(), format :: atom()) :: map() def embedded_dump(%schema{} = data, format) do Ecto.Schema.Loader.safe_dump(data, schema.__schema__(:dump), &Ecto.Type.embedded_dump(&1, &2, format)) diff --git a/lib/ecto/repo.ex b/lib/ecto/repo.ex index dc4e7e8669..48e9851e1c 100644 --- a/lib/ecto/repo.ex +++ b/lib/ecto/repo.ex @@ -92,7 +92,20 @@ defmodule Ecto.Repo do * `:telemetry_options` - Extra options to attach to telemetry event name. See the next section for more information - ### Telemetry events + ## Telemetry events + + There are two types of telemetry events. The ones emitted by Ecto and the + ones that are adapter specific. + + ### Ecto telemetry events + + The following events are emitted by all Ecto repositories: + + * `[:ecto, :repo, :init]` - it is invoked whenever a repository starts. + The measurement is a single `system_time` entry in native unit. The + metadata is the `:repo` and all initialization options under `:opts`. + + ### Adapter-specific events We recommend adapters to publish certain `Telemetry` events listed below. Those events will use the `:telemetry_prefix` outlined above which defaults