# `Lotus.Storage.TypeMapper`
[🔗](https://github.com/typhoonworks/lotus/blob/v0.16.6/lib/lotus/storage/type_mapper.ex#L1)

Maps database column types to Lotus internal types for automatic casting.

Different databases use different type names for the same logical types.
This module normalizes those differences into a consistent set of Lotus types
that can be used for automatic value casting.

## Supported Databases

- **PostgreSQL**: uuid, integer, numeric, date, timestamp, text, boolean, json, etc.
- **MySQL**: char(36), binary(16), int, decimal, date, datetime, varchar, json, etc.
- **SQLite**: INTEGER, REAL, TEXT, BLOB, etc. (dynamic typing)

## Usage

    # Map PostgreSQL UUID to Lotus type
    TypeMapper.db_type_to_lotus_type("uuid", Lotus.Sources.Postgres)
    # => :uuid

    # Map MySQL UUID storage to Lotus type
    TypeMapper.db_type_to_lotus_type("char(36)", Lotus.Sources.MySQL)
    # => :uuid

    # Get Ecto type for casting
    TypeMapper.lotus_type_to_ecto_type(:uuid)
    # => Ecto.UUID

# `lotus_type`

```elixir
@type lotus_type() ::
  :uuid
  | :integer
  | :float
  | :decimal
  | :boolean
  | :date
  | :time
  | :datetime
  | :json
  | :binary
  | :text
  | :enum
  | :composite
  | {:array, lotus_type()}
```

# `db_type_to_lotus_type`

```elixir
@spec db_type_to_lotus_type(
  db_type :: String.t(),
  source_module :: module()
) :: lotus_type()
```

Convert database-specific type to Lotus internal type.

Uses source module to determine database flavor and map accordingly.

## Examples

    db_type_to_lotus_type("uuid", Lotus.Sources.Postgres)
    # => :uuid

    db_type_to_lotus_type("char(36)", Lotus.Sources.MySQL)
    # => :uuid

    db_type_to_lotus_type("INTEGER", Lotus.Sources.SQLite3)
    # => :integer

# `lotus_type_to_ecto_type`

```elixir
@spec lotus_type_to_ecto_type(lotus_type()) :: atom() | {:array, atom()}
```

Returns the Ecto type equivalent for a Lotus type.

Used for casting values via Ecto's type system.

## Examples

    lotus_type_to_ecto_type(:uuid)
    # => Ecto.UUID

    lotus_type_to_ecto_type(:integer)
    # => :integer

---

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