title: Which functions are called 'under the hood' when using Ecto.Repo in elixir
body: <p>I am trying to get a better understanding of Ecto adapters in elixir. I have begun trying to build my own adapter using <a href="https://github.com/elixir-ecto/ecto_sql/blob/master/lib/ecto/adapters/postgres.ex" rel="noreferrer"><code>Ecto.Adapters.Postgres</code></a> as a base. This seemed like a good choice to start with as it is the default adapter used with Phoenix. </p>
  
  <p>I can use my adapter in my own projects now by updating the the following line in my project's repo file...</p>
  
  <pre><code>defmodule UsingTestAdapter.Repo do
    use Ecto.Repo,
      otp_app: :using_test_adapter,
      adapter: TestAdapter  # &lt;------ this line
  end
  </code></pre>
  
  <p>At the moment it has the same functionality as the postgres adapter. I have been trying to edit some of the functions found in the <a href="https://github.com/elixir-ecto/ecto_sql/blob/master/lib/ecto/adapters/postgres/connection.ex" rel="noreferrer"><code>Ecto.Adapters.Postgres.Connection</code></a> and I have realised that they do not work quite how I expected. </p>
  
  <p>The <a href="https://github.com/elixir-ecto/ecto_sql/blob/master/lib/ecto/adapters/postgres/connection.ex#L151" rel="noreferrer"><code>insert</code></a> function for example does not actually use the params passed into <code>Repo.insert</code>. </p>
  
  <p>To make this a little more clear imagine we have the following table, <code>Comments</code>...</p>
  
  <pre><code>| id | comment |
  | -- | ------- |
  </code></pre>
  
  <p>Now <code>Repo.insert(%Comments{comment: "hi"})</code> is called.</p>
  
  <p>I want to modify the adapter, so that it ignores the "hi" value that is passed in and instead inserts a comment of "I am the adapter, and I control this database. Hahaha (evil laugh)"...</p>
  
  <pre><code>| id | comment                                                            |
  | -- | ------------------------------------------------------------------ |
  | 1  | I am the adapter and I control this database. Hahaha (evil laugh)" |
  </code></pre>
  
  <p>However, the <code>insert</code> function does not appear to actually take the data to be stored as an argument.</p>
  
  <p>My initial thought of what happened with ecto adapters was that when a user calls one of the repo functions it called the corresponding function in the <code>Ecto.Adapters.Postgres.Connection</code> module. This does appear to happen but other steps seem to be happening before this. </p>
  
  <p>If anyone has a better understanding of the chain of functions that are called when <code>Repo.insert</code> (and any other Repo function) is called, please explain below.</p>