From 94808f3794047cb851b74078186e003fe148b056 Mon Sep 17 00:00:00 2001 From: Robert Francis Date: Thu, 28 Feb 2019 13:13:28 +0000 Subject: [PATCH] adds remaining defdelgate to required functions #45 --- lib/alog.ex | 20 ++++++++++++------ lib/alog/connection.ex | 46 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/lib/alog.ex b/lib/alog.ex index e0fde26..0b15510 100644 --- a/lib/alog.ex +++ b/lib/alog.ex @@ -3,16 +3,24 @@ defmodule Alog do driver: :postgrex, migration_lock: "FOR UPDATE" - @impl true - def supports_ddl_transaction? do - true - end + alias Ecto.Adapters.Postgres, as: EAP @behaviour Ecto.Adapter.Storage + # Why did we define our own version of this function? + # Sorry if I have missed something that has been explained already. + @impl true + def supports_ddl_transaction?, do: true + + @impl true + defdelegate storage_up(opts), to: EAP + + @impl true + defdelegate storage_down(opts), to: EAP + @impl true - defdelegate storage_up(opts), to: Ecto.Adapters.Postgres + defdelegate structure_dump(default, config), to: EAP @impl true - defdelegate storage_down(opts), to: Ecto.Adapters.Postgres + defdelegate structure_load(default, config), to: EAP end diff --git a/lib/alog/connection.ex b/lib/alog/connection.ex index 775cbd2..9cbc0fe 100644 --- a/lib/alog/connection.ex +++ b/lib/alog/connection.ex @@ -1,16 +1,52 @@ defmodule Alog.Connection do + alias Ecto.Adapters.Postgres.Connection, as: EAPC + @behaviour Ecto.Adapters.SQL.Connection + @default_port 5432 + + @impl true + def child_spec(opts) do + opts + |> Keyword.put_new(:port, @default_port) + |> Postgrex.child_spec() + end + + @impl true + defdelegate ddl_logs(result), to: EAPC + + @impl true + defdelegate prepare_execute(conn, name, statement, params, opts), to: EAPC + + @impl true + defdelegate query(conn, statement, params, opts), to: EAPC + + @impl true + defdelegate stream(conn, statement, params, opts), to: EAPC + + @impl true + defdelegate to_constraints(error_struct), to: EAPC + + @impl true + defdelegate execute(conn, query, params, opts), to: EAPC + + @impl true + defdelegate all(query), to: EAPC + + @impl true + defdelegate update_all(query, prefix \\ nil), to: EAPC + + @impl true + defdelegate delete_all(query), to: EAPC @impl true - defdelegate ddl_logs(result), to: Ecto.Adapter.Postgres + defdelegate insert(prefix, table, header, rows, on_conflict, returning), to: EAPC @impl true - defdelegate prepare_execute(connection, name, statement, params, options), - to: Ecto.Adapter.Postgres + defdelegate update(prefix, table, fields, filters, returning), to: EAPC @impl true - defdelegate query(connection, statement, params, options), to: Ecto.Adapter.Postgres + defdelegate delete(prefix, table, filters, returning), to: EAPC @impl true - defdelegate stream(connection, statement, params, options), to: Ecto.Adapter.Postgres + defdelegate execute_ddl(arg), to: EAPC end