Stores a string in the database.
A built-in type that can be referenced via :string.
By default, values are trimmed and empty values are set to nil.
You can use the allow_empty? and trim? constraints to change these behaviors.
Constraints
:max_length(non_neg_integer/0) - Enforces a maximum length on the value:min_length(non_neg_integer/0) - Enforces a minimum length on the value:length_count- The unit used bymin_lengthandmax_length. Defaults to the unit implied byconfig :ash, :default_string_length_count(:codepoints, or:graphemesfor:mixed).:graphemesmatchesString.length/1.:codepointsmatches how most SQL data layers count string length.:bytesmatchesbyte_size/1.
A single grapheme may contain an unbounded number of codepoints (a base character followed by many combining marks), so:graphemesplaces no effective limit on the size of a value. Prefer:codepointsor:byteswhenmax_lengthis used as a storage or safety limit.
Data layers cannot count graphemes, so with an explicit:graphemesthe length constraints can only be applied to literal values, not atomically to expressions. Valid values are :graphemes, :codepoints, :bytes:match(Regex.t/0) - Enforces that the string matches a passed in regex:trim?(boolean/0) - Trims the value. The default value istrue.:allow_empty?(boolean/0) - If false, the value is set tonilif it's empty. The default value isfalse.
Summary
Functions
The default unit for counting string length, derived from
config :ash, :default_string_length_count.
Functions
@spec default_length_count() :: :graphemes | :codepoints
The default unit for counting string length, derived from
config :ash, :default_string_length_count.
:codepoints(recommended, set by the installer) counts codepoints, matching SQL data layers and bounding the size of values.:mixedkeeps the previous behavior: graphemes are counted in Elixir, while atomic expressions defer to the data layer's own length function.
The configuration is required. See the backwards compatibility guide for more. Individual attributes and validations can still choose any unit.