Localize.Territory.Ecto.Type (Localize SQL v1.0.0)

Copy Markdown View Source

An Ecto.Type storing a territory as its code in a text column.

A territory is identified by its ISO 3166-1 / CLDR code — :US, :GB, :"001" (the world) — and that code is what is stored, in an ordinary text column. Values cast and load as the validated code atom, so a stored territory can carry a unique index or a CHECK constraint like any other text, and an unknown territory is rejected on the way in.

Schema

# in a migration
add :country, :string

# in a schema
field :country, Localize.Territory.Ecto.Type

Casting

cast/1 accepts a code as an atom (:US) or a string ("US", in any case), including UN M49 region codes as strings — "001" for the world, "150" for Europe. Country-level M49 numbers such as "840" are not CLDR territory codes (use "US"). Codes are validated against Localize.validate_territory/1.

Summary

Functions

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

Functions

embed_as(_)

Callback implementation for Ecto.Type.embed_as/1.

equal?(term1, term2)

Callback implementation for Ecto.Type.equal?/2.