Skip to content

Commit

Permalink
adds remaining defdelgate to required functions #45
Browse files Browse the repository at this point in the history
  • Loading branch information
RobStallion committed Feb 28, 2019
1 parent 33f3102 commit 94808f3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
20 changes: 14 additions & 6 deletions lib/alog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 41 additions & 5 deletions lib/alog/connection.ex
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 94808f3

Please sign in to comment.