View Source Tds.Ecto.VarChar (Ecto SQL v3.11.1)

An Tds adapter Ecto Type that wraps erlang string into tuple so TDS driver can understand if erlang string should be encoded as NVarChar or Varchar.

Due to some limitations in Ecto and Tds driver, it is not possible to support collations other than the one set on connection during login. Please be aware of this limitation if you plan to store varchar values in your database using Ecto since you will probably lose some codepoints in the value during encoding. Instead use tds_encoding library and first encode value and then annotate it as :binary by calling Ecto.Query.API.type/2 in your query. This way all codepoints will be properly preserved during insert to database.

Summary

Types

t()

An erlang string

A value annotated as varchar.

Functions

Casts to string.

Same as cast/1 but raises Ecto.CastError on invalid arguments.

Converts a string representing a VarChar into a tuple {value, :varchar}.

Callback implementation for Ecto.Type.embed_as/1.

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

Loads the DB type as is.

Types

@type t() :: String.t()

An erlang string

@type varchar() :: {String.t(), :varchar}

A value annotated as varchar.

Functions

@spec cast(t() | varchar() | any()) :: {:ok, t()} | :error

Casts to string.

@spec cast!(t() | varchar() | any()) :: t()

Same as cast/1 but raises Ecto.CastError on invalid arguments.

@spec dump(t() | any()) :: {:ok, varchar()} | :error

Converts a string representing a VarChar into a tuple {value, :varchar}.

Returns :error if value is not binary.

Callback implementation for Ecto.Type.embed_as/1.

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

@spec load(t() | any()) :: {:ok, t()} | :error

Loads the DB type as is.