Packages
exandra
0.1.10
1.1.0
1.0.0
0.16.0
0.15.0
0.14.0
0.13.0
0.12.0
0.11.0
0.10.3
0.10.2
0.10.1
0.10.1-rc.5
0.10.0
0.10.0-rc.5
0.10.0-rc.4
0.10.0-rc.3
0.10.0-rc.2
0.10.0-rc.1
0.9.1
0.9.0
0.8.1
0.8.0
0.7.5
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.1
0.5.0
0.4.1
0.4.0
0.3.1
0.3.0
0.2.1
0.2.0
0.1.16
0.1.15
0.1.14
0.1.13
0.1.12
0.1.11
0.1.10
Exandra is an Elixir library that brings the power of Scylla/Cassandra to Ecto.
Current section
Files
Jump to
Current section
Files
lib/exandra/types.ex
defmodule Exandra.Types do
alias Exandra.Types.XMap
alias Exandra.Types.XSet
alias Exandra.Types.UDT
def apply(type, op, value, opts) do
cond do
is_atom(type) and function_exported?(type, op, 1) ->
apply(type, op, [value])
is_atom(type) and function_exported?(type, op, 2) ->
apply(type, op, [value, opts])
true ->
Ecto.Type.cast(type, value)
end
end
def for(type, opts \\ [])
def for(:id, _), do: :uuid
def for(:binary_id, _), do: :uuid
def for(:integer, _), do: :int
def for(:string, _), do: :text
def for(:binary, _), do: :blob
def for(:map, _), do: :text
def for(UDT, opts) do
type = Keyword.get(opts, :type)
if is_nil(type), do: raise(ArgumentError, "must define :type option for UDT column")
"FROZEN<#{type}>"
end
def for(t, _opts) when t in [:datetime, :naive_datetime, :utc_datetime, :utc_datetime_usec],
do: :timestamp
def for({:parameterized, Ecto.Embedded, _}, _opts), do: :text
def for({:parameterized, Ecto.Enum, _}, _opts), do: :text
def for({:parameterized, XMap, opts}, _opts), do: XMap.xandra_type(opts)
def for({:parameterized, XSet, opts}, _opts), do: XSet.xandra_type(opts)
def for({:set, opts}, _opts), do: XSet.type(opts)
def for(ecto_type, _opts) do
if is_atom(ecto_type) and function_exported?(ecto_type, :type, 0) do
ecto_type.type()
else
ecto_type
end
end
end