mirror of
https://github.com/ash-project/ash_csv.git
synced 2024-09-19 12:53:31 +12:00
chore: fix issues from optimization
This commit is contained in:
parent
255f11a37c
commit
2665e5cc52
4 changed files with 39 additions and 61 deletions
|
@ -1,2 +1,2 @@
|
|||
erlang 26.0.2
|
||||
elixir 1.15.4
|
||||
elixir 1.16.2
|
||||
|
|
|
@ -202,17 +202,10 @@ defmodule AshCsv.DataLayer do
|
|||
if pkey_value in record_pkeys do
|
||||
{:halt, {:error, "Record #{inspect(pkey_value)} is not unique"}}
|
||||
else
|
||||
row =
|
||||
Enum.reduce_while(columns(resource), {:ok, []}, fn key, {:ok, row} ->
|
||||
value = Map.get(changeset.attributes, key)
|
||||
|
||||
{:cont, {:ok, [to_string(value) | row]}}
|
||||
end)
|
||||
|
||||
case row do
|
||||
case dump_row(resource, changeset) do
|
||||
{:ok, row} ->
|
||||
lines =
|
||||
[Enum.reverse(row)]
|
||||
[row]
|
||||
|> CSV.encode(separator: separator(resource))
|
||||
|> Enum.to_list()
|
||||
|
||||
|
@ -559,55 +552,40 @@ defmodule AshCsv.DataLayer do
|
|||
results =
|
||||
resource
|
||||
|> file()
|
||||
|> File.stream!()
|
||||
|> Stream.drop(amount_to_drop)
|
||||
|> CSV.decode(separator: separator(resource))
|
||||
|> then(fn csv_stream ->
|
||||
cond do
|
||||
decode? && is_nil(filter) && sort in [nil, []] ->
|
||||
csv_stream
|
||||
|> offset_stream(offset)
|
||||
|> limit_stream(limit)
|
||||
|> Stream.map(fn
|
||||
{:error, error} ->
|
||||
throw({:error, error})
|
||||
|> then(fn file ->
|
||||
if decode? do
|
||||
file
|
||||
|> File.stream!()
|
||||
|> Stream.drop(amount_to_drop)
|
||||
|> CSV.decode(separator: separator(resource))
|
||||
|> Stream.map(fn
|
||||
{:error, error} ->
|
||||
throw({:error, error})
|
||||
|
||||
{:ok, row} ->
|
||||
case cast_stored(resource, row) do
|
||||
{:ok, casted} -> casted
|
||||
{:error, error} -> throw({:error, error})
|
||||
end
|
||||
end)
|
||||
|> Enum.to_list()
|
||||
{:ok, row} ->
|
||||
case cast_stored(resource, row) do
|
||||
{:ok, casted} -> casted
|
||||
{:error, error} -> throw({:error, error})
|
||||
end
|
||||
end)
|
||||
|> filter_stream(domain, filter)
|
||||
|> sort_stream(resource, domain, sort)
|
||||
|> offset_stream(offset)
|
||||
|> limit_stream(limit)
|
||||
|> Enum.to_list()
|
||||
else
|
||||
file
|
||||
|> File.stream!()
|
||||
|> Stream.drop(amount_to_drop)
|
||||
|> CSV.decode(separator: separator(resource))
|
||||
|> Stream.map(fn
|
||||
{:error, error} ->
|
||||
throw({:error, error})
|
||||
|
||||
decode? ->
|
||||
csv_stream
|
||||
|> Stream.map(fn
|
||||
{:error, error} ->
|
||||
throw({:error, error})
|
||||
|
||||
{:ok, row} ->
|
||||
case cast_stored(resource, row) do
|
||||
{:ok, casted} -> casted
|
||||
{:error, error} -> throw({:error, error})
|
||||
end
|
||||
end)
|
||||
|> filter_stream(domain, filter)
|
||||
|> sort_stream(resource, domain, sort)
|
||||
|> offset_stream(offset)
|
||||
|> limit_stream(limit)
|
||||
|> Enum.to_list()
|
||||
|
||||
true ->
|
||||
csv_stream
|
||||
|> Stream.map(fn
|
||||
{:error, error} ->
|
||||
throw({:error, error})
|
||||
|
||||
{:ok, row} ->
|
||||
row
|
||||
end)
|
||||
|> Enum.to_list()
|
||||
{:ok, row} ->
|
||||
row
|
||||
end)
|
||||
|> Enum.to_list()
|
||||
end
|
||||
end)
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ defmodule AshCsv.DataLayer.Transformers.BuildParser do
|
|||
:error ->
|
||||
throw(
|
||||
{:error,
|
||||
"stored value for #{unquote(column)} could not be cast to type #{unquote(Macro.escape(attribute.type))}: #{inspect(value)}"}
|
||||
"stored value for #{unquote(column)} could not be casted from the stored value to type #{unquote(inspect(Macro.escape(attribute.type)))}: #{inspect(value)}"}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -60,7 +60,7 @@ defmodule AshCsv.DataLayer.Transformers.BuildParser do
|
|||
value = unquote(matcher)
|
||||
|
||||
unquote(matcher) =
|
||||
case Ash.Type.dump_to_native(
|
||||
case Ash.Type.dump_to_embedded(
|
||||
unquote(Macro.escape(attribute.type)),
|
||||
value,
|
||||
unquote(Macro.escape(attribute.constraints))
|
||||
|
@ -71,7 +71,7 @@ defmodule AshCsv.DataLayer.Transformers.BuildParser do
|
|||
:error ->
|
||||
throw(
|
||||
{:error,
|
||||
"stored value for #{unquote(column)} could not be cast to type #{unquote(Macro.escape(attribute.type))}: #{inspect(value)}"}
|
||||
"stored value for #{unquote(column)} could not be dumped to type #{inspect(unquote(Macro.escape(attribute.type)))}: #{inspect(value)}"}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
2
mix.lock
2
mix.lock
|
@ -1,5 +1,5 @@
|
|||
%{
|
||||
"ash": {:hex, :ash, "3.0.0-rc.5", "351ed5a675c0e0adb001634303a498cc6feda6c9ba0f30c080645bc5fbd8b5b4", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 0.8", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.1.7 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.6", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3356375e6488a6ac821a641394986beb495e7a84c4b169ed3d841635b40bbc71"},
|
||||
"ash": {:hex, :ash, "3.0.0-rc.46", "8c84ca24003c3e678f84f51da79a6b3edd1d808ccace53e207776e7d15a8c5f7", [:mix], [{:comparable, "~> 1.0", [hex: :comparable, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, ">= 0.8.1 and < 1.0.0-0", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.1.18 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.2", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 0.6", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c833ba90e76a17cf5b9386bc47626d943f5da0908a5e7b850433f9db3e79784c"},
|
||||
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
|
||||
"comparable": {:hex, :comparable, "1.0.0", "bb669e91cedd14ae9937053e5bcbc3c52bb2f22422611f43b6e38367d94a495f", [:mix], [{:typable, "~> 0.1", [hex: :typable, repo: "hexpm", optional: false]}], "hexpm", "277c11eeb1cd726e7cd41c6c199e7e52fa16ee6830b45ad4cdc62e51f62eb60c"},
|
||||
"credo": {:hex, :credo, "1.7.5", "643213503b1c766ec0496d828c90c424471ea54da77c8a168c725686377b9545", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "f799e9b5cd1891577d8c773d245668aa74a2fcd15eb277f51a0131690ebfb3fd"},
|
||||
|
|
Loading…
Reference in a new issue