View Source Resourceful.Type.Ecto (Resourceful v0.1.4)
Creates a Resourceful.Type
from an Ecto.Schema
module. The use case
is that internal data will be represented by the schema and client-facing data
will be represented by the resource definition. Additionally, field names may
be mapped differently to the client, such as camel case values. This can be
done individually or with a single function as an option.
Since Resourceful.Type
instances use the same type system as Ecto, this
is a relatively straightforward conversion.
Link to this section Summary
Functions
Returns a Resourceful.Type.Attribute
based on a field from an Ecto.Schema
module.
Returns a Resourceful.Type
from an Ecto.Schema
module by inferring
values from the schema.
Link to this section Functions
@spec attribute(module(), atom(), keyword()) :: %Resourceful.Type.Attribute{ embedded_type: term(), filter?: term(), map_to: term(), name: term(), sort?: term(), type: term() }
Returns a Resourceful.Type.Attribute
based on a field from an Ecto.Schema
module.
@spec type_with_schema( module(), keyword() ) :: %Resourceful.Type{ cache: term(), fields: term(), id: term(), max_depth: term(), max_filters: term(), max_sorters: term(), meta: term(), name: term(), registry: term() }
Returns a Resourceful.Type
from an Ecto.Schema
module by inferring
values from the schema.
options
Options
For most options, a list of schema field names (atoms) will be passed in
specifying the type's configuration for those fields. In these cases a value
of true
or :all
will result in all fields being used. For example if you
wanted to be able to query all fields, you would pass [query: :all]
.
:except
- Schema fields to be excluded from the type.:filter
- Schema fields allowed to be filtered.:only
- Schema fields to be included in the type.:query
- Schema fields allowed to be queried (sorted and filtered).:sort
- Schema fields allowed to be sorted.:transform_names
- A single argument function that takes the field name (an atom) and transforms it into either another atom or a string. A type of case conversion is the most likely use case.
Addionally, any options not mentioned above will be passed directly to
Resourceful.Type.new/2
.