Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trim input fields
Browse files Browse the repository at this point in the history
MikaelFangel committed Oct 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 970b872 commit fc386a8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/kino_db/connection_cell.ex
Original file line number Diff line number Diff line change
@@ -217,6 +217,13 @@ defmodule KinoDB.ConnectionCell do
Enum.any?(keys, fn key -> attrs[key] not in [nil, ""] end)
end

defp trim_opts(opts) do
Enum.map(opts, fn
{key, value} when is_binary(value) -> {key, String.trim(value)}
{key, value} -> {key, value}
end)
end

defp to_quoted(%{"type" => "sqlite"} = attrs) do
quote do
opts = [database: unquote(attrs["database_path"])]
@@ -254,23 +261,23 @@ defmodule KinoDB.ConnectionCell do

defp to_quoted(%{"type" => "postgres"} = attrs) do
quote do
opts = unquote(shared_options(attrs) ++ postgres_and_mysql_options(attrs))
opts = unquote(trim_opts(shared_options(attrs) ++ postgres_and_mysql_options(attrs)))

{:ok, unquote(quoted_var(attrs["variable"]))} = Kino.start_child({Postgrex, opts})
end
end

defp to_quoted(%{"type" => "mysql"} = attrs) do
quote do
opts = unquote(shared_options(attrs) ++ postgres_and_mysql_options(attrs))
opts = unquote(trim_opts(shared_options(attrs) ++ postgres_and_mysql_options(attrs)))

{:ok, unquote(quoted_var(attrs["variable"]))} = Kino.start_child({MyXQL, opts})
end
end

defp to_quoted(%{"type" => "sqlserver"} = attrs) do
quote do
opts = unquote(shared_options(attrs) ++ sqlserver_options(attrs))
opts = unquote(trim_opts(shared_options(attrs) ++ sqlserver_options(attrs)))

{:ok, unquote(quoted_var(attrs["variable"]))} = Kino.start_child({Tds, opts})
end

0 comments on commit fc386a8

Please sign in to comment.