Inspecto.Schema (inspecto v0.3.0)

This defines the shape of Ecto schema inspections.

Link to this section Summary

Functions

Inspects the given Ecto schema module. This will return an :invalid_module tuple if the given module does not define an Ecto schema (this isn't 100% accurate, but it's unlikely that other modules would coincidentally define the same functions as an Ecto schema).

Link to this section Types

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

Link to this section Functions

Link to this function

inspect(module)

@spec inspect(module :: module()) :: {:ok, t()} | {:invalid_module, module()}

Inspects the given Ecto schema module. This will return an :invalid_module tuple if the given module does not define an Ecto schema (this isn't 100% accurate, but it's unlikely that other modules would coincidentally define the same functions as an Ecto schema).

examples

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)
{:invalid_module, Enum}