File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4646### Runtime Configuration
4747
4848``` elixir
49- config :exqlite , default_chunk_size: 100
49+ config :exqlite ,
50+ default_chunk_size: 100 ,
51+ type_extensions: [MyApp .TypeExtension ]
5052```
5153
5254* ` default_chunk_size ` - The chunk size that is used when multi-stepping when
5355 not specifying the chunk size explicitly.
54-
56+ * ` type_extensions ` : An optional list of modules that implement the
57+ Exqlite.TypeExtension behaviour, allowing types beyond the default set that
58+ can be stored and retrieved from the database.
59+
5560### Compile-time Configuration
5661
5762In ` config/config.exs ` ,
Original file line number Diff line number Diff line change 1+ defmodule Exqlite.TypeExtension do
2+ @ moduledoc """
3+ A behaviour that defines the API for extensions providing custom data loaders and dumpers
4+ for Ecto schemas.
5+ """
6+
7+ @ doc """
8+ Takes a value and convers it to data suitable for storage in the database.
9+ """
10+ @ callback convert ( value :: term ) :: term
11+ end
Original file line number Diff line number Diff line change @@ -481,5 +481,20 @@ defmodule Exqlite.Sqlite3 do
481481 raise ArgumentError , "#{ inspect ( datetime ) } is not in UTC"
482482 end
483483
484- defp convert ( val ) , do: val
484+ defp convert ( val ) do
485+ convert_with_type_extensions ( type_extensions ( ) , val )
486+ end
487+
488+ defp convert_with_type_extensions ( [ ] , val ) , do: val
489+
490+ defp convert_with_type_extensions ( [ extension | other_extensions ] , val ) do
491+ case extension . convert ( val ) do
492+ nil -> convert_with_type_extensions ( other_extensions , val )
493+ convert -> convert
494+ end
495+ end
496+
497+ defp type_extensions ( ) do
498+ Application . get_env ( :exqlite , :type_extensions , [ ] )
499+ end
485500end
You can’t perform that action at this time.
0 commit comments