View Source Tds.Ecto.VarChar (Ecto SQL v3.8.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 some limitations in Ecto and Tds driver, it is not possible to support collations other than the one that is 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.

Link to this section Summary

Types

t()

A erlang string

A value annotated as varchar.

Functions

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

Casts to string.

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.

Link to this section Types

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

A erlang string

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

A value annotated as varchar.

Link to this section Functions

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

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

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

Casts to string.

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