Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/exqlite/sqlite3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,19 @@ defmodule Exqlite.Sqlite3 do

defp convert_with_type_extensions([extension | other_extensions], val) do
case extension.convert(val) do
nil -> convert_with_type_extensions(other_extensions, val)
convert -> convert
nil ->
convert_with_type_extensions(other_extensions, val)

{:ok, converted} ->
converted

{:error, reason} ->
raise ArgumentError,
"Failed conversion by TypeExtension #{extension}: #{inspect(val)}. Reason: #{inspect(reason)}."
end
end

defp type_extensions() do
defp type_extensions do
Application.get_env(:exqlite, :type_extensions, [])
end
end
5 changes: 4 additions & 1 deletion lib/exqlite/extension.ex → lib/exqlite/type_extension.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ defmodule Exqlite.TypeExtension do

@doc """
Takes a value and convers it to data suitable for storage in the database.

Returns a tagged :ok/:error tuple. If the value is not convertable by this
extension, returns nil.
"""
@callback convert(value :: term) :: term
@callback convert(value :: term) :: {:ok, term} | {:error, reason :: term} | nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's just an atom, but perhaps :unsupported is more clear than nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I didn't use a more "expressive" atom is one ends up having to remember all the various names for "this is not something that is happening" return values. nil is convenient in that it is the least surprising (at least for me) and widely used to mean "nothing here".

If you prefer, I can change it to :unsupported, but as a library user I lean towards "common and therefore predictable" in these cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No that's a fine justification.

end