Add support for Postgrex 0.13 and Ecto 2.1

This commit is contained in:
Igor Barchenkov 2017-04-21 13:00:31 +03:00
parent 50e4b6adca
commit 8dde5562d1
4 changed files with 22 additions and 15 deletions

View File

@ -6,11 +6,18 @@ defmodule ISN do
A Postgrex.Extension enabling the use of postgresql data types from the isn
extension.
Add this module as an extension when establishing your Postgrex connection:
In lib/ directory create a file called postgrex_types.ex with the following content:
Postgrex.start_link(
database: "isn_test",
extensions: [{ISN, {}}])
Postgrex.Types.define(
MyApp.PostgrexTypes,
[ISN] ++ Ecto.Adapters.Postgres.extensions(),
json: Poison
)
Add the following lines in conig.exs:
config :my_app, MyApp.Repo,
types: MyApp.PostgrexTypes
Then you can do Ecto.Migrations like this:
@ -31,13 +38,13 @@ defmodule ISN do
use MyApp.Web, :model
schema "books" do
field :isbn, ISN.ISBN13
field :isbn, ISN.ISBN13, read_after_writes: true
# other fields
end
end
"""
def init(opts) when opts in [:copy, :reference], do: opts
def init(opts), do: Keyword.get(opts, :decode_copy, :reference)
def matching(_),
do: Enum.zip(Stream.cycle([:type]), @isn)

View File

@ -41,9 +41,9 @@ defmodule ISN.Mixfile do
end
defp deps do
[{:postgrex, ">= 0.9.1"},
{:ecto, ">= 1.0.0"},
{:credo, "~> 0.1", only: :dev},
{:ex_doc, "~> 0.10", only: :dev}]
[{:postgrex, ">= 0.13.2"},
{:ecto, ">= 2.1.4"},
{:credo, "~> 0.7", only: :dev},
{:ex_doc, "~> 0.15", only: :dev}]
end
end

View File

@ -1,11 +1,11 @@
%{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], []},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], []},
"credo": {:hex, :credo, "0.6.1", "a941e2591bd2bd2055dc92b810c174650b40b8290459c89a835af9d59ac4a5f8", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, optional: false]}]},
"db_connection": {:hex, :db_connection, "1.1.1", "f9d246e8f65b9490945cf7360875eee18fcec9a0115207603215eb1fd94c39ef", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
"credo": {:hex, :credo, "0.7.3", "9827ab04002186af1aec014a811839a06f72aaae6cd5eed3919b248c8767dbf3", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, optional: false]}]},
"db_connection": {:hex, :db_connection, "1.1.2", "2865c2a4bae0714e2213a0ce60a1b12d76a6efba0c51fbda59c9ab8d1accc7a8", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
"decimal": {:hex, :decimal, "1.3.1", "157b3cedb2bfcb5359372a7766dd7a41091ad34578296e951f58a946fcab49c6", [:mix], []},
"earmark": {:hex, :earmark, "1.1.1", "433136b7f2e99cde88b745b3a0cfc3fbc81fe58b918a09b40fce7f00db4d8187", [:mix], []},
"ecto": {:hex, :ecto, "2.1.3", "ffb24e150b519a4c0e4c84f9eabc8587199389bc499195d5d1a93cd3b2d9a045", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
"ecto": {:hex, :ecto, "2.1.4", "d1ba932813ec0e0d9db481ef2c17777f1cefb11fc90fa7c142ff354972dfba7e", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, optional: true]}]},
"eh": {:hex, :eh, "0.2.0"},
"ex_doc": {:hex, :ex_doc, "0.15.0", "e73333785eef3488cf9144a6e847d3d647e67d02bd6fdac500687854dd5c599f", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []},
"postgrex": {:hex, :postgrex, "0.13.1", "ebf17b7348922af9db8b4d70f946328ab9ef5123526bf05567d9306393fce104", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}}
"postgrex": {:hex, :postgrex, "0.13.2", "2b88168fc6a5456a27bfb54ccf0ba4025d274841a7a3af5e5deb1b755d95154e", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}}

View File

@ -1,7 +1,7 @@
ExUnit.start()
Postgrex.Types.define(
ISN.PostgrexTypes,
[{ISN, :reference}],
[ISN],
[])
defmodule ISN.TestHelper do