Inspecto.Schema (inspecto v0.4.0)

Formalized reflection data about an Ecto schema.

Summary

Functions

Summarizes the given Ecto schema module as an %Inspecto.Schema{} struct.

Types

t()

@type t() :: %Inspecto.Schema{
  fields: [Inspecto.Schema.Field.t()],
  module: module(),
  prefix: atom() | nil,
  primary_key: [atom()],
  source: String.t() | nil
}

Functions

inspect(module, opts \\ [])

@spec inspect(module :: module(), opts :: Keyword.t()) ::
  {:ok, t()} | {:error, module()}

Summarizes the given Ecto schema module as an %Inspecto.Schema{} struct.

An error is returned if the given module does not define an Ecto schema (technically, this isn't 100% accurate, but it's unlikely that other modules would coincidentally define the same functions as an Ecto schema).

Options

Examples

iex> Inspecto.Schema.inspect(MyApp.Schemas.MyThing)
{:ok, %Inspecto.Schema{
  module: MyApp.Schemas.MyThing,
  source: "things",
  primary_key: [:id],
  fields: [
    %Inspecto.Schema.Field{name: :id, type: :integer, default: nil},
    %Inspecto.Schema.Field{name: :name, type: :string, default: ""},
    %Inspecto.Schema.Field{name: :created_at, type: :naive_datetime, default: nil},
  ]
}}

iex> Inspecto.Schema.inspect(Enum)
{:error, Enum}

inspect_field(module, fieldname, opts \\ [])