Skip to content

Commit 86dca78

Browse files
committed
Rename :type formatter to :map
1 parent bddffa2 commit 86dca78

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

lib/feeb/db/repo.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ defmodule Feeb.DB.Repo do
283283

284284
defp format_result(:one, _, _, [row], _, %{format: :raw}), do: {:ok, row}
285285

286-
defp format_result(:one, query_id, query, [row], _, %{format: :type}),
287-
do: {:ok, create_types_from_rows(query_id, query, [row]) |> List.first()}
286+
defp format_result(:one, query_id, query, [row], _, %{format: :map}),
287+
do: {:ok, create_maps_from_rows(query_id, query, [row]) |> List.first()}
288288

289289
defp format_result(:one, query_id, query, [row], _, _),
290290
do: {:ok, create_schema_from_rows(query_id, query, [row]) |> List.first()}
@@ -295,13 +295,13 @@ defmodule Feeb.DB.Repo do
295295
defp format_result(:all, _, _, [], _, _), do: {:ok, []}
296296
defp format_result(:all, _, _, rows, _, %{format: :raw}), do: {:ok, rows}
297297

298-
defp format_result(:all, query_id, query, rows, _, %{format: :type}),
299-
do: {:ok, create_types_from_rows(query_id, query, rows)}
298+
defp format_result(:all, query_id, query, rows, _, %{format: :map}),
299+
do: {:ok, create_maps_from_rows(query_id, query, rows)}
300300

301301
defp format_result(:all, query_id, query, rows, _, %{format: :schema}),
302302
do: {:ok, create_schema_from_rows(query_id, query, rows)}
303303

304-
defp format_result(:insert, _, _, [], _, %{format: format}) when format in [:raw, :type],
304+
defp format_result(:insert, _, _, [], _, %{format: format}) when format in [:raw, :map],
305305
do: {:ok, nil}
306306

307307
defp format_result(:insert, query_id, query, [], bindings, %{format: :schema}) do
@@ -364,7 +364,7 @@ defmodule Feeb.DB.Repo do
364364
Enum.map(rows, fn row -> Schema.from_row(model, model.__cols__(), row) end)
365365
end
366366

367-
defp create_types_from_rows(query_id, {_, {fields_bindings, _}, :select} = query, rows) do
367+
defp create_maps_from_rows(query_id, {_, {fields_bindings, _}, :select} = query, rows) do
368368
# Performance-wise, not the best solution, but I'd rather keep the code readable for a bit
369369
# longer. Simply create the full schema and use only the fields the user selected
370370
create_schema_from_rows(query_id, query, rows)

test/db/db_test.exs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -462,20 +462,20 @@ defmodule Feeb.DBTest do
462462
assert ["i_am_atom", 50] == DB.one({:all_types, :get_atom_and_integer}, [], format: :raw)
463463
assert ["{\"foo\":\"bar\"}"] == DB.one({:all_types, :get_map_keys_atom}, [], format: :raw)
464464

465-
# With the :type flag, we return the values formatted by their types _without_ the full schema
465+
# With the :map flag, we return the values formatted by their types _without_ the full schema
466466
assert %{map_keys_atom: %{foo: "bar"}} ==
467-
DB.one({:all_types, :get_map_keys_atom}, [], format: :type)
467+
DB.one({:all_types, :get_map_keys_atom}, [], format: :map)
468468

469469
assert %{atom: :i_am_atom, integer: 50} ==
470-
DB.one({:all_types, :get_atom_and_integer}, [], format: :type)
470+
DB.one({:all_types, :get_atom_and_integer}, [], format: :map)
471471

472472
# Custom selection with different formats
473473
assert ["Phoebe"] = DB.one({:friends, :fetch}, [1], select: [:name], format: :raw)
474-
assert %{name: "Phoebe"} = DB.one({:friends, :fetch}, [1], select: [:name], format: :type)
474+
assert %{name: "Phoebe"} = DB.one({:friends, :fetch}, [1], select: [:name], format: :map)
475475

476476
# No matching results
477477
assert nil == DB.one({:friends, :fetch}, [500], select: [:name], format: :raw)
478-
assert nil == DB.one({:friends, :fetch}, [500], select: [:name], format: :type)
478+
assert nil == DB.one({:friends, :fetch}, [500], select: [:name], format: :map)
479479
end
480480

481481
test "works with window functions when using :raw flag", %{shard_id: shard_id} do
@@ -583,21 +583,21 @@ defmodule Feeb.DBTest do
583583
assert [["{\"foo\":\"bar\"}"], ["{\"girl\":[\"so\",\"confusing\"]}"]] |> Enum.sort() ==
584584
DB.all({:all_types, :get_map}, [], format: :raw) |> Enum.sort()
585585

586-
# With the :type flag, we return the values formatted by their types _without_ the full schema
586+
# With the :map flag, we return the values formatted by their types _without_ the full schema
587587
assert [%{map: %{girl: ["so", "confusing"]}}, %{map: %{foo: "bar"}}] |> Enum.sort() ==
588-
DB.all({:all_types, :get_map}, [], format: :type) |> Enum.sort()
588+
DB.all({:all_types, :get_map}, [], format: :map) |> Enum.sort()
589589

590590
assert [%{atom: :i_am_atom, integer: 50}, %{atom: :other_atom, integer: -2}] |> Enum.sort() ==
591-
DB.all({:all_types, :get_atom_and_integer}, [], format: :type) |> Enum.sort()
591+
DB.all({:all_types, :get_atom_and_integer}, [], format: :map) |> Enum.sort()
592592

593593
# Custom selection with different formats
594594
assert [%{name: "Phoebe"}] =
595-
DB.all({:friends, :get_by_name}, "Phoebe", select: [:name], format: :type)
595+
DB.all({:friends, :get_by_name}, "Phoebe", select: [:name], format: :map)
596596

597597
assert [["Joey"]] = DB.all({:friends, :get_by_name}, "Joey", select: [:name], format: :raw)
598598

599599
# No matching results
600-
assert [] == DB.all({:friends, :get_by_name}, "Michael Scott", format: :type)
600+
assert [] == DB.all({:friends, :get_by_name}, "Michael Scott", format: :map)
601601
end
602602
end
603603

0 commit comments

Comments
 (0)