Skip to content

Commit

Permalink
Applying suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
cristineguadelupe committed Aug 30, 2023
1 parent 41ec919 commit c13b736
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/kino_db/connection_cell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ defmodule KinoDB.ConnectionCell do
end

defp to_quoted(%{"type" => "snowflake"} = attrs) do
var = quoted_var(attrs["variable"])

quote do
:ok = Adbc.download_driver!(:snowflake)
uri = unquote(build_snowflake_uri(attrs))
{:ok, db} = Kino.start_child({Adbc.Database, driver: :snowflake, uri: uri})

{:ok, unquote(quoted_var(attrs["variable"]))} =
Kino.start_child({Adbc.Connection, database: db})
{:ok, unquote(var)} = Kino.start_child({Adbc.Connection, database: db})
end
end

Expand Down
13 changes: 4 additions & 9 deletions lib/kino_db/sql_cell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ defmodule KinoDB.SQLCell do
_ -> nil
end
else
_ -> connection_from_adbc(connection)
_ -> connection_type_from_adbc(connection)
end
end

Expand All @@ -136,10 +136,10 @@ defmodule KinoDB.SQLCell do

defp connection_type(_connection), do: nil

defp connection_from_adbc(connection) when is_pid(connection) do
defp connection_type_from_adbc(connection) when is_pid(connection) do
with true <- Code.ensure_loaded?(Adbc),
true <- is_snowflake_conn?(connection) do
"snowflake"
{:ok, driver} <- Adbc.Connection.get_driver(connection) do
Atom.to_string(driver)
else
_ -> nil
end
Expand Down Expand Up @@ -284,9 +284,4 @@ defmodule KinoDB.SQLCell do
defp parameterize(<<char::utf8, rest::binary>>, raw, params, n, next) do
parameterize(rest, <<raw::binary, char::utf8>>, params, n, next)
end

defp is_snowflake_conn?(conn) when conn == self(), do: false
defp is_snowflake_conn?(conn) when is_pid(conn), do: is_snowflake_conn?(:sys.get_state(conn))
defp is_snowflake_conn?(%{queue: _, lock: _, conn: conn}) when is_reference(conn), do: true
defp is_snowflake_conn?(_), do: false
end

0 comments on commit c13b736

Please sign in to comment.