Skip to content

Commit

Permalink
reorder type encoding
Browse files Browse the repository at this point in the history
Because `nil` is technically an atom, we need to ensure that it gets encoded before we attempt to encode other atoms as `sql_varchars`.  This commit moves the `nil` case clause to a more appropriate location.
  • Loading branch information
mphfish committed Dec 13, 2022
1 parent 61fe9cb commit ffcc04e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/snowflex/type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ defmodule Snowflex.Type do
def encode(true, _), do: {:sql_integer, [1]}
def encode(false, _), do: {:sql_integer, [0]}

def encode(nil, _) do
{:sql_integer, [:null]}
end

def encode(param, _) when is_integer(param), do: {:sql_integer, [param]}

def encode(param, _) when is_float(param), do: {:sql_double, [param]}
Expand Down Expand Up @@ -81,10 +85,6 @@ defmodule Snowflex.Type do
end
end

def encode(nil, _) do
{:sql_integer, [:null]}
end

def encode(value, _) do
raise Snowflex.Error.exception(
message: "could not parse param #{inspect(value)} of unrecognised type."
Expand Down

0 comments on commit ffcc04e

Please sign in to comment.