diff --git a/README.md b/README.md index 58621c2..6683ec0 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,10 @@ config :my_app, MyApp.SnowflakeConnection, ] ``` +The odbc driver will, by default, return `:null` for empty values returned from snowflake queries. +This will be converted to `nil` by default by Snowflex. A configuration value `map_nulls_to_nil?` +can be set to `false` if you do not desire this behavior. + Then, in your application module, you would start your connection: ```elixir diff --git a/lib/snowflex.ex b/lib/snowflex.ex index ec9f552..7526aa9 100644 --- a/lib/snowflex.ex +++ b/lib/snowflex.ex @@ -75,6 +75,8 @@ defmodule Snowflex do end defp process_results({:selected, headers, rows}) do + null_to_nil? = Application.get_env(:snowflex, :map_nulls_to_nil?, true) + bin_headers = headers |> Enum.map(fn header -> header |> to_string() |> String.downcase() end) @@ -86,6 +88,7 @@ defmodule Snowflex do row |> elem(index) |> to_string_if_charlist() + |> map_null_to_nil(null_to_nil?) Map.put(map, col, data) end) @@ -95,6 +98,9 @@ defmodule Snowflex do defp to_string_if_charlist(data) when is_list(data), do: to_string(data) defp to_string_if_charlist(data), do: data + defp map_null_to_nil(:null, true), do: nil + defp map_null_to_nil(data, _), do: data + defp cast_row(row, schema) do schema |> struct()