Sigra.Ecto.Types.StringList (Sigra v0.2.5)

Copy Markdown View Source

Custom Ecto type for storing lists as comma-separated strings.

Useful for MySQL/SQLite databases that lack native array column types. In PostgreSQL, prefer {:array, :string} for native array support.

Storage Format

Lists are stored as comma-separated strings in the database:

["profile:read", "sessions:write"] -> "profile:read,sessions:write"

Usage

field :scopes, Sigra.Ecto.Types.StringList

Summary

Functions

Casts external input to a list of strings.

Dumps a list to a comma-separated string for database storage.

Callback implementation for Ecto.Type.embed_as/1.

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

Loads a comma-separated string from the database into a list.

Returns the underlying database type (:string).

Functions

cast(list)

Casts external input to a list of strings.

Accepts both lists and comma-separated strings.

dump(list)

Dumps a list to a comma-separated string for database storage.

embed_as(_)

Callback implementation for Ecto.Type.embed_as/1.

equal?(term1, term2)

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

load(string)

Loads a comma-separated string from the database into a list.

Returns {:ok, []} for nil values (no scopes stored).

type()

Returns the underlying database type (:string).