Use PostgreSQL binary wire procotol
Mostly to make `isn` compatible with postgrex 0.13.0. This will probably also make the extension a bit more performant.
This commit is contained in:
parent
056012ad97
commit
9ea1f173f7
25
lib/isn.ex
25
lib/isn.ex
|
|
@ -39,8 +39,7 @@ defmodule ISN do
|
|||
end
|
||||
"""
|
||||
|
||||
def init(parameters, _opts),
|
||||
do: parameters
|
||||
def init(opts) when opts in [:copy, :reference], do: opts
|
||||
|
||||
def matching(_),
|
||||
do: Enum.zip(Stream.cycle([:type]), @isn)
|
||||
|
|
@ -48,11 +47,25 @@ defmodule ISN do
|
|||
def format(_),
|
||||
do: :text
|
||||
|
||||
def encode(%TypeInfo{type: type}, binary, _types, _opts) when type in @isn,
|
||||
do: binary
|
||||
def encode(opts) do
|
||||
quote do
|
||||
thing ->
|
||||
[<<IO.iodata_length(thing) :: int32>> | thing]
|
||||
end
|
||||
end
|
||||
|
||||
def decode(%TypeInfo{type: type}, binary, _types, _opts) when type in @isn,
|
||||
do: binary
|
||||
def decode(:copy) do
|
||||
quote do
|
||||
<<len :: int32, thing::binary-size(len)>> ->
|
||||
:binary.copy(thing)
|
||||
end
|
||||
end
|
||||
def decode(:reference) do
|
||||
quote do
|
||||
<<len :: int32, thing::binary-size(len)>> ->
|
||||
thing
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Generate Ecto.Type modules for all supported data types in the `isn`
|
||||
|
|
|
|||
16
mix.lock
16
mix.lock
|
|
@ -1,11 +1,11 @@
|
|||
%{"bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [:mix], []},
|
||||
"connection": {:hex, :connection, "1.0.3", "3145f7416be3df248a4935f24e3221dc467c1e3a158d62015b35bd54da365786", [:mix], []},
|
||||
"credo": {:hex, :credo, "0.4.5", "5c5daaf50a2a96068c0f21b6fbd382d206702efa8836a946eeab0b8ac25f5f22", [:mix], [{:bunt, "~> 0.1.6", [hex: :bunt, optional: false]}]},
|
||||
"db_connection": {:hex, :db_connection, "1.0.0-rc.3", "d9ceb670fe300271140af46d357b669983cd16bc0d01206d7d3222dde56cf038", [:mix], [{:sbroker, "~> 1.0.0-beta.3", [hex: :sbroker, optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: true]}, {:connection, "~> 1.0.2", [hex: :connection, optional: false]}]},
|
||||
"decimal": {:hex, :decimal, "1.1.2", "79a769d4657b2d537b51ef3c02d29ab7141d2b486b516c109642d453ee08e00c", [:mix], []},
|
||||
"earmark": {:hex, :earmark, "1.0.1", "2c2cd903bfdc3de3f189bd9a8d4569a075b88a8981ded9a0d95672f6e2b63141", [:mix], []},
|
||||
"ecto": {:hex, :ecto, "2.0.2", "b02331c1f20bbe944dbd33c8ecd8f1ccffecc02e344c4471a891baf3a25f5406", [:mix], [{:poison, "~> 1.5 or ~> 2.0", [hex: :poison, optional: true]}, {:sbroker, "~> 1.0-beta", [hex: :sbroker, optional: true]}, {:mariaex, "~> 0.7.7", [hex: :mariaex, optional: true]}, {:postgrex, "~> 0.11.2", [hex: :postgrex, optional: true]}, {:db_connection, "~> 1.0-rc.2", [hex: :db_connection, optional: true]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, optional: false]}]},
|
||||
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], []},
|
||||
"credo": {:hex, :credo, "0.5.3", "0c405b36e7651245a8ed63c09e2d52c2e2b89b6d02b1570c4d611e0fcbecf4a2", [:mix], [{:bunt, "~> 0.1.6", [hex: :bunt, optional: false]}]},
|
||||
"db_connection": {:hex, :db_connection, "1.1.0", "b2b88db6d7d12f99997b584d09fad98e560b817a20dab6a526830e339f54cdb3", [: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.0.3", "89bdbaf2aca8bbb5c97d8b3b55c5dd0cff517ecc78d417e87f1d0982e514557b", [: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]}]},
|
||||
"eh": {:hex, :eh, "0.2.0"},
|
||||
"ex_doc": {:hex, :ex_doc, "0.13.0", "aa2f8fe4c6136a2f7cfc0a7e06805f82530e91df00e2bff4b4362002b43ada65", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
|
||||
"ex_doc": {:hex, :ex_doc, "0.14.5", "c0433c8117e948404d93ca69411dd575ec6be39b47802e81ca8d91017a0cf83c", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
|
||||
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], []},
|
||||
"postgrex": {:hex, :postgrex, "0.11.2", "139755c1359d3c5c6d6e8b1ea72556d39e2746f61c6ddfb442813c91f53487e8", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.0-rc", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}}
|
||||
"postgrex": {:hex, :postgrex, "0.13.0", "e101ab47d0725955c5c8830ae8812412992e02e4bd9db09e17abb0a5d82d09c7", [:mix], [{:connection, "~> 1.0", [hex: :connection, optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, optional: false]}]}}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,32 @@
|
|||
ExUnit.start()
|
||||
Postgrex.Types.define(
|
||||
ISN.PostgrexTypes,
|
||||
[{ISN, :reference}],
|
||||
[])
|
||||
|
||||
defmodule ISN.TestHelper do
|
||||
def conn_options do
|
||||
db_options = [
|
||||
sync_connect: true,
|
||||
hostname: "localhost",
|
||||
types: ISN.PostgrexTypes,
|
||||
database: "isn_test"]
|
||||
|
||||
db_user = System.get_env("DATABASE_POSTGRESQL_USERNAME")
|
||||
db_pass = System.get_env("DATABASE_POSTGRESQL_PASSWORD")
|
||||
|
||||
db_options =
|
||||
if db_user, do: db_options = Dict.put(db_options, :username, db_user),
|
||||
else: db_options
|
||||
if db_user do
|
||||
Map.put(db_options, :username, db_user)
|
||||
else
|
||||
db_options
|
||||
end
|
||||
db_options =
|
||||
if db_pass, do: db_options = Dict.put(db_options, :password, db_pass),
|
||||
else: db_options
|
||||
if db_pass do
|
||||
Map.put(db_options, :password, db_pass)
|
||||
else
|
||||
db_options
|
||||
end
|
||||
|
||||
db_options
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue