Skip to content

Commit 0d0d604

Browse files
Merge pull request #30 from renatomassaro/add-telemetry
Add Telemetry support
2 parents 1c563f0 + 5545307 commit 0d0d604

11 files changed

Lines changed: 220 additions & 124 deletions

File tree

lib/feeb/db.ex

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ defmodule Feeb.DB do
2828

2929
# We can't BEGIN EXCLUSIVE in a read-only database
3030
txn_type = if(access_type == :read, do: :deferred, else: transaction_type)
31-
:ok = GenServer.call(get_pid!(), {:begin, txn_type})
31+
:ok = Repo.begin(get_pid!(), txn_type)
3232
end
3333

3434
@doc """
@@ -58,9 +58,7 @@ defmodule Feeb.DB do
5858
It will also release the lock in the Repo connection, allowing other processes to grab it.
5959
"""
6060
def commit do
61-
:ok = GenServer.call(get_pid!(), {:commit})
62-
# TODO: Close via repomanager
63-
# :ok = GenServer.call(get_pid!(), {:close})
61+
:ok = Repo.commit(get_pid!())
6462
delete_env()
6563
:ok
6664
end
@@ -71,7 +69,7 @@ defmodule Feeb.DB do
7169
It will also release the lock in the Repo connection, allowing other processes to grab it.
7270
"""
7371
def rollback do
74-
:ok = GenServer.call(get_pid!(), {:rollback})
72+
:ok = Repo.rollback(get_pid!())
7573
delete_env()
7674
:ok
7775
end
@@ -81,19 +79,14 @@ defmodule Feeb.DB do
8179
##################################################################################################
8280

8381
def raw(sql, bindings \\ []) do
84-
GenServer.call(get_pid!(), {:raw, sql, bindings})
82+
Repo.raw(get_pid!(), sql, bindings)
8583
end
8684

8785
def raw!(sql, bindings \\ []) do
8886
{:ok, r} = raw(sql, bindings)
8987
r
9088
end
9189

92-
def prepared_raw(sql, bindings, schema) do
93-
opts = [schema: schema]
94-
GenServer.call(get_pid!(), {:prepared_raw, sql, bindings, opts})
95-
end
96-
9790
def one(partial_or_full_query_id, bindings \\ [], opts \\ [])
9891

9992
def one({domain, :fetch}, bindings, opts) when is_list(bindings) do
@@ -115,7 +108,7 @@ defmodule Feeb.DB do
115108
def one({domain, query_name}, value, opts), do: one({domain, query_name}, [value], opts)
116109

117110
def one({_, domain, query_name}, bindings, opts) when is_list(bindings) do
118-
case GenServer.call(get_pid!(), {:query, :one, {domain, query_name}, bindings, opts}) do
111+
case Repo.one(get_pid!(), {domain, query_name}, bindings, opts) do
119112
{:ok, r} -> r
120113
{:error, :multiple_results} -> raise "MultipleResultsError"
121114
end
@@ -146,7 +139,7 @@ defmodule Feeb.DB do
146139
def all({domain, query_name}, value, opts), do: all({domain, query_name}, [value], opts)
147140

148141
def all({_, domain, query_name}, bindings, opts) do
149-
case GenServer.call(get_pid!(), {:query, :all, {domain, query_name}, bindings, opts}) do
142+
case Repo.all(get_pid!(), {domain, query_name}, bindings, opts) do
150143
{:ok, rows} -> rows
151144
{:error, reason} -> raise reason
152145
end
@@ -169,7 +162,7 @@ defmodule Feeb.DB do
169162

170163
if struct.__meta__.valid? do
171164
bindings = get_bindings(full_query_id, struct)
172-
GenServer.call(get_pid!(), {:query, :insert, {domain, query_name}, bindings, opts})
165+
Repo.insert(get_pid!(), {domain, query_name}, bindings, opts)
173166
else
174167
{:error, "Cast error: #{inspect(struct.__meta__.errors)}"}
175168
end
@@ -191,7 +184,7 @@ defmodule Feeb.DB do
191184
true = :db == struct.__meta__.origin
192185

193186
bindings = get_bindings(full_query_id, struct)
194-
GenServer.call(get_pid!(), {:query, :update, {domain, query_name}, bindings, opts})
187+
Repo.update(get_pid!(), {domain, query_name}, bindings, opts)
195188
end
196189

197190
def update_all(partial_or_full_query_id, bindings, opts \\ [])
@@ -201,7 +194,7 @@ defmodule Feeb.DB do
201194
end
202195

203196
def update_all({_, domain, query_name}, bindings, opts) do
204-
GenServer.call(get_pid!(), {:query, :update_all, {domain, query_name}, bindings, opts})
197+
Repo.update_all(get_pid!(), {domain, query_name}, bindings, opts)
205198
end
206199

207200
def update_all!(query_id, params, opts \\ []) do
@@ -225,7 +218,7 @@ defmodule Feeb.DB do
225218
true = :db == struct.__meta__.origin
226219

227220
bindings = get_bindings(full_query_id, struct)
228-
GenServer.call(get_pid!(), {:query, :delete, {domain, query_name}, bindings, opts})
221+
Repo.delete(get_pid!(), {domain, query_name}, bindings, opts)
229222
end
230223

231224
def delete_all(partial_or_full_query_id, bindings, opts \\ [])
@@ -235,7 +228,7 @@ defmodule Feeb.DB do
235228
end
236229

237230
def delete_all({_, domain, query_name}, bindings, opts) do
238-
GenServer.call(get_pid!(), {:query, :delete_all, {domain, query_name}, bindings, opts})
231+
Repo.delete_all(get_pid!(), {domain, query_name}, bindings, opts)
239232
end
240233

241234
def delete_all!(query_id, params, opts \\ []) do
@@ -274,6 +267,7 @@ defmodule Feeb.DB do
274267
##################################################################################################
275268

276269
defp setup_env(context, shard_id, type, opts) when type in [:write, :read] do
270+
# TODO: shard-aware telemetry
277271
{:ok, manager_pid} = Repo.Manager.Registry.fetch_or_create(context, shard_id)
278272
{:ok, repo_pid} = Repo.Manager.fetch_connection(manager_pid, type, opts)
279273

lib/feeb/db/application.ex

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)