Created
March 11, 2015 18:31
-
-
Save alanpeabody/1d42022eaa89b34aa221 to your computer and use it in GitHub Desktop.
embedding elixir structs part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Extensions.JSON do | |
alias Postgrex.TypeInfo | |
@behaviour Postgrex.Extension | |
@json ["json", "jsonb"] | |
def init(_parameters, opts), | |
do: Keyword.fetch!(opts, :library) | |
def matching(_library), | |
do: [type: "json", type: "jsonb"] | |
def format(_library), | |
do: :binary | |
def encode(%TypeInfo{type: type}, map, _state, library) when type in @json, | |
do: library.encode!(map) | |
def decode(%TypeInfo{type: type}, json, _state, library) when type in @json, | |
do: library.decode!(json) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment