# `Localize.Territory.Ecto.Type`
[🔗](https://github.com/elixir-localize/localize_sql/blob/v1.0.1/lib/localize/territory/ecto/type.ex#L1)

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`.

# `embed_as`

# `equal?`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
