-
Notifications
You must be signed in to change notification settings - Fork 64
Add Exqlite.TypeExtensions to allow more types to be stored in the database #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| defmodule Exqlite.TypeExtension do | ||
| @moduledoc """ | ||
| A behaviour that defines the API for extensions providing custom data loaders and dumpers | ||
| for Ecto schemas. | ||
| """ | ||
|
|
||
| @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) :: {:ok, term} | {:error, reason :: term} | nil | ||
|
Comment on lines
+9
to
+13
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it's just an atom, but perhaps
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. If you prefer, I can change it to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No that's a fine justification. |
||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going back and fourth on allowing
type_extensionsto benil.On one hand, letting it default to nil, will make the pattern match be faster than matching with an empty list.
And then changing
Application.get_env(:exqlite, :type_extensions, [])to beApplication.get_env(:exqlite, :type_extensions).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went back and forth as well .. I'm not sure the speed gain is really going to be noticeable, but it's easy enough to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See 704c9bd