diff --git a/lib/assets/connection_cell/main.js b/lib/assets/connection_cell/main.js index 862a191..5ef1b4e 100644 --- a/lib/assets/connection_cell/main.js +++ b/lib/assets/connection_cell/main.js @@ -815,23 +815,35 @@ export function init(ctx, info) { props: { fields: { type: Object, - default: { - base_url: "http://localhost:8123" - }, + default: {}, }, }, template: `
+ +
if fields["use_password_secret"], - do: ~w|base_url username password_secret database|, - else: ~w|base_url username password database| + do: ~w|hostname port use_ssl username password_secret database|, + else: ~w|hostname port use_ssl username password database| type when type in ["postgres", "mysql"] -> if fields["use_password_secret"], @@ -195,7 +195,7 @@ defmodule KinoDB.ConnectionCell do ~w|hostname port| "clickhouse" -> - ~w|base_url| + ~w|hostname port| type when type in ["postgres", "mysql"] -> ~w|hostname port| @@ -338,9 +338,7 @@ defmodule KinoDB.ConnectionCell do clickhouse_opts = trimmed |> clickhouse_options(shared_opts) quote do - opts = unquote(clickhouse_opts) - - unquote(quoted_var(attrs["variable"])) = {:clickhouse, opts} + unquote(quoted_var(attrs["variable"])) = ReqCH.new(unquote(clickhouse_opts)) :ok end @@ -447,18 +445,31 @@ defmodule KinoDB.ConnectionCell do end defp clickhouse_options(attrs) do - [ - base_url: attrs["base_url"] || "http://localhost:8123" - ] + scheme = if attrs["use_ssl"], do: "https", else: "http" + + [scheme: scheme] end defp clickhouse_options(attrs, shared_options) do attrs |> clickhouse_options() + |> build_clickhouse_base_url(shared_options) |> maybe_add_req_basic_auth(shared_options) |> maybe_add_clickhouse_database(shared_options) end + defp build_clickhouse_base_url(opts, shared_opts) do + host = Keyword.fetch!(shared_opts, :hostname) + port = Keyword.fetch!(shared_opts, :port) + scheme = Keyword.fetch!(opts, :scheme) + + uri = %URI{scheme: scheme, port: port, host: host} + + opts + |> Keyword.put_new(:base_url, URI.to_string(uri)) + |> Keyword.delete(:scheme) + end + defp maybe_add_req_basic_auth(opts, shared_opts) do username = shared_opts[:username] @@ -543,16 +554,10 @@ defmodule KinoDB.ConnectionCell do end defp missing_dep(%{"type" => "athena"}) do - deps = [ + missing_many_deps([ {ReqAthena, ~s|{:req_athena, "~> 0.1"}|}, {Explorer, ~s|{:explorer, "~> 0.9"}|} - ] - - deps = for {module, dep} <- deps, not Code.ensure_loaded?(module), do: dep - - if deps != [] do - Enum.join(deps, ", ") - end + ]) end defp missing_dep(%{"type" => adbc}) when adbc in ~w[snowflake duckdb] do @@ -568,11 +573,15 @@ defmodule KinoDB.ConnectionCell do end defp missing_dep(%{"type" => "clickhouse"}) do - deps = [ + missing_many_deps([ {ReqCH, ~s|{:req_ch, git: "https://github.com/livebook-dev/req_ch.git"}|}, {Explorer, ~s|{:explorer, "~> 0.10"}|} - ] + ]) + end + + defp missing_dep(_ctx), do: nil + defp missing_many_deps(deps) do deps = for {module, dep} <- deps, not Code.ensure_loaded?(module), do: dep if deps != [] do @@ -580,8 +589,6 @@ defmodule KinoDB.ConnectionCell do end end - defp missing_dep(_ctx), do: nil - defp join_quoted(quoted_blocks) do asts = Enum.flat_map(quoted_blocks, fn diff --git a/lib/kino_db/sql_cell.ex b/lib/kino_db/sql_cell.ex index c7c667e..9294901 100644 --- a/lib/kino_db/sql_cell.ex +++ b/lib/kino_db/sql_cell.ex @@ -167,11 +167,11 @@ defmodule KinoDB.SQLCell do cond do Keyword.has_key?(connection.request_steps, :bigquery_run) -> "bigquery" Keyword.has_key?(connection.request_steps, :athena_run) -> "athena" + Keyword.has_key?(connection.request_steps, :clickhouse_run) -> "clickhouse" true -> nil end end - defp connection_type({:clickhouse, _}), do: "clickhouse" defp connection_type(_connection), do: nil defp connection_type_from_adbc(connection) when is_pid(connection) do @@ -220,6 +220,21 @@ defmodule KinoDB.SQLCell do to_quoted(attrs, quote(do: Tds), fn n -> "@#{n}" end) end + # query!/4 based that returns a Req response. + defp to_quoted(%{"connection" => %{"type" => "clickhouse"}} = attrs) do + to_quoted_query_req(attrs, quote(do: ReqCH), fn n, inner -> + # TODO: we may need to better specify the type here. + name = + if String.match?(inner, ~r/[^a-z0-9_]/) do + "param_#{n}" + else + inner + end + + "{#{name}:String}" + end) + end + # Explorer-based defp to_quoted(%{"connection" => %{"type" => "snowflake"}} = attrs) do to_explorer_quoted(attrs, fn n -> "?#{n}" end) @@ -238,33 +253,26 @@ defmodule KinoDB.SQLCell do to_req_quoted(attrs, fn _n -> "?" end, :athena) end - # ClichHouse - defp to_quoted(%{"connection" => %{"type" => "clickhouse"}} = attrs) do - {query, params} = - parameterize(attrs["query"], attrs["connection"]["type"], fn _n, ident -> - "{#{ident}:String}" - end) + defp to_quoted(_ctx) do + quote do + end + end - dbg(query) - dbg(params) + defp to_quoted_query_req(attrs, quoted_module, next) do + {query, params} = parameterize(attrs["query"], attrs["connection"]["type"], next) + opts_args = query_opts_args(attrs) quote do - {:clickhouse, req_ch_opts} = unquote(quoted_var(attrs["connection"]["variable"])) - unquote(quoted_var(attrs["result_variable"])) = - ReqCH.query!( - unquote(query), + unquote(quoted_module).query!( + unquote(quoted_var(attrs["connection"]["variable"])), + unquote(quoted_query(query)), unquote(params), - req_ch_opts + unquote_splicing(opts_args) ).body end end - defp to_quoted(_ctx) do - quote do - end - end - defp to_quoted(attrs, quoted_module, next) do {query, params} = parameterize(attrs["query"], attrs["connection"]["type"], next) opts_args = query_opts_args(attrs) @@ -329,6 +337,9 @@ defmodule KinoDB.SQLCell do defp query_opts_args(%{"connection" => %{"type" => "athena"}, "cache_query" => cache_query}), do: [[cache_query: cache_query]] + defp query_opts_args(%{"connection" => %{"type" => "clickhouse"}}), + do: [[format: :explorer]] + defp query_opts_args(_attrs), do: [] defp parameterize(query, type, next) do @@ -376,11 +387,14 @@ defmodule KinoDB.SQLCell do defp apply_next(next, n, _inner) when is_function(next, 1), do: next.(n) defp apply_next(next, n, inner) when is_function(next, 2), do: next.(n, inner) - defp quote_param("clickhouse", inner, _sql_param) do + defp quote_param("clickhouse", inner, sql_param) do with {:ok, inner_ast} <- Code.string_to_quoted(inner) do + name = + sql_param |> String.trim_leading("{") |> String.split(":", parts: 2) |> List.first() + {:ok, quote do - {unquote(inner), unquote(inner_ast)} + {unquote(name), unquote(inner_ast)} end} end end diff --git a/mix.exs b/mix.exs index 1c5c418..bfe7319 100644 --- a/mix.exs +++ b/mix.exs @@ -34,11 +34,13 @@ defmodule KinoDB.MixProject do {:myxql, "~> 0.7", optional: true}, {:postgrex, "~> 0.18 or ~> 1.0", optional: true}, {:tds, "~> 2.3.4 or ~> 2.4", optional: true}, - {:explorer, "~> 0.8", optional: true}, + {:explorer, "~> 0.10", optional: true}, # Those dependecies are new, so we use stricter versions {:req_bigquery, "~> 0.1.0", optional: true}, {:req_athena, "~> 0.2.0", optional: true}, + {:req_ch, + git: "https://github.com/livebook-dev/req_ch.git", branch: "ps-add-query-4", optional: true}, # Dev only {:ex_doc, "~> 0.28", only: :dev, runtime: false} diff --git a/mix.lock b/mix.lock index 22b1456..8c56c62 100644 --- a/mix.lock +++ b/mix.lock @@ -1,15 +1,15 @@ %{ - "adbc": {:hex, :adbc, "0.6.1", "66e8f53bb952514de836d0bb362f091df5f87102dd649b4a812668315acacb9f", [:make, :mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:cc_precompiler, "~> 0.1.8 or ~> 0.2", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:decimal, "~> 2.1", [hex: :decimal, repo: "hexpm", optional: false]}, {:dll_loader_helper_beam, "~> 1.0", [hex: :dll_loader_helper_beam, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.8", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "226ae3eaa58d1616a7594bc49cbdc02ba60bb92afd6b6cbe392789dd0e627789"}, + "adbc": {:hex, :adbc, "0.6.5", "fb480706f10324acc6f8894d4e06e208a44e4ec2df8c72001ecb0b6e41de059b", [:make, :mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:cc_precompiler, "~> 0.1.8 or ~> 0.2", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:decimal, "~> 2.1", [hex: :decimal, repo: "hexpm", optional: false]}, {:dll_loader_helper_beam, "~> 1.0", [hex: :dll_loader_helper_beam, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.8", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "e1c2fc14fb9cc1b09f89616a980101ac4dd67d01e95b81d47480ba414e02d824"}, "aws_signature": {:hex, :aws_signature, "0.3.2", "adf33bc4af00b2089b7708bf20e3246f09c639a905a619b3689f0a0a22c3ef8f", [:rebar3], [], "hexpm", "b0daf61feb4250a8ab0adea60db3e336af732ff71dd3fb22e45ae3dcbd071e44"}, - "castore": {:hex, :castore, "1.0.8", "dedcf20ea746694647f883590b82d9e96014057aff1d44d03ec90f36a5c0dc6e", [:mix], [], "hexpm", "0b2b66d2ee742cb1d9cb8c8be3b43c3a70ee8651f37b75a8b982e036752983f1"}, + "castore": {:hex, :castore, "1.0.10", "43bbeeac820f16c89f79721af1b3e092399b3a1ecc8df1a472738fd853574911", [:mix], [], "hexpm", "1b0b7ea14d889d9ea21202c43a4fa015eb913021cb535e8ed91946f4b77a8848"}, "cc_precompiler": {:hex, :cc_precompiler, "0.1.10", "47c9c08d8869cf09b41da36538f62bc1abd3e19e41701c2cea2675b53c704258", [:mix], [{:elixir_make, "~> 0.7", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "f6e046254e53cd6b41c6bacd70ae728011aa82b2742a80d6e2214855c6e06b22"}, "db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"}, - "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, + "decimal": {:hex, :decimal, "2.2.0", "df3d06bb9517e302b1bd265c1e7f16cda51547ad9d99892049340841f3e15836", [:mix], [], "hexpm", "af8daf87384b51b7e611fb1a1f2c4d4876b65ef968fa8bd3adf44cff401c7f21"}, "dll_loader_helper_beam": {:hex, :dll_loader_helper_beam, "1.2.2", "b86f97ec8fc64770c87468e41969eb309d87b29dd5a439b667e5954f85f8f65a", [:rebar3], [], "hexpm", "0e6119edde0ef5e42b4fe22d7dc71b7462e08573cee977c01a26ec5d9cd94a9a"}, "earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"}, - "elixir_make": {:hex, :elixir_make, "0.8.4", "4960a03ce79081dee8fe119d80ad372c4e7badb84c493cc75983f9d3bc8bde0f", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "6e7f1d619b5f61dfabd0a20aa268e575572b542ac31723293a4c1a567d5ef040"}, + "elixir_make": {:hex, :elixir_make, "0.9.0", "6484b3cd8c0cee58f09f05ecaf1a140a8c97670671a6a0e7ab4dc326c3109726", [:mix], [], "hexpm", "db23d4fd8b757462ad02f8aa73431a426fe6671c80b200d9710caf3d1dd0ffdb"}, "ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"}, - "explorer": {:hex, :explorer, "0.9.2", "a9598eeff8d36d88f643d14818bea1869ca70c4def61bfba22f040ee315b84b6", [:mix], [{:adbc, "~> 0.1", [hex: :adbc, repo: "hexpm", optional: true]}, {:aws_signature, "~> 0.3", [hex: :aws_signature, repo: "hexpm", optional: false]}, {:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:flame, "~> 0.3", [hex: :flame, repo: "hexpm", optional: true]}, {:fss, "~> 0.1", [hex: :fss, repo: "hexpm", optional: false]}, {:nx, "~> 0.4", [hex: :nx, repo: "hexpm", optional: true]}, {:rustler, "~> 0.34.0", [hex: :rustler, repo: "hexpm", optional: true]}, {:rustler_precompiled, "~> 0.7", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}, {:table, "~> 0.1.2", [hex: :table, repo: "hexpm", optional: false]}, {:table_rex, "~> 3.1.1 or ~> 4.0.0", [hex: :table_rex, repo: "hexpm", optional: false]}], "hexpm", "63057e318d613c1819bd8bee2d8ed4f7061c3136edc6832ad18243d28e6344eb"}, + "explorer": {:hex, :explorer, "0.10.0", "ba690afb59fce81746a1b6c9d25294aabcb9bae783ceeb43f5fd4834e1e16d78", [:mix], [{:adbc, "~> 0.1", [hex: :adbc, repo: "hexpm", optional: true]}, {:aws_signature, "~> 0.3", [hex: :aws_signature, repo: "hexpm", optional: false]}, {:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:decimal, "~> 2.1", [hex: :decimal, repo: "hexpm", optional: false]}, {:flame, "~> 0.3", [hex: :flame, repo: "hexpm", optional: true]}, {:fss, "~> 0.1", [hex: :fss, repo: "hexpm", optional: false]}, {:nx, "~> 0.4", [hex: :nx, repo: "hexpm", optional: true]}, {:rustler, "~> 0.34.0", [hex: :rustler, repo: "hexpm", optional: true]}, {:rustler_precompiled, "~> 0.7", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}, {:table, "~> 0.1.2", [hex: :table, repo: "hexpm", optional: false]}, {:table_rex, "~> 3.1.1 or ~> 4.0.0", [hex: :table_rex, repo: "hexpm", optional: false]}], "hexpm", "874b6af1f711186f391b507af293995f89311821486e01cbca4c99777ff20864"}, "exqlite": {:hex, :exqlite, "0.20.0", "99b711eb1a3309b380ff54901d3d7db8e7afaf4b68a34398a69e1fa1b9b2054e", [:make, :mix], [{:cc_precompiler, "~> 0.1", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.8", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "385ed37b8317101b7f9b58333910798ebe395e77ee6ca261be74a1a06b3d61f6"}, "finch": {:hex, :finch, "0.19.0", "c644641491ea854fc5c1bbaef36bfc764e3f08e7185e1f084e35e0672241b76d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.6.2 or ~> 1.7", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fc5324ce209125d1e2fa0fcd2634601c52a787aff1cd33ee833664a5af4ea2b6"}, "fss": {:hex, :fss, "0.1.1", "9db2344dbbb5d555ce442ac7c2f82dd975b605b50d169314a20f08ed21e08642", [:mix], [], "hexpm", "78ad5955c7919c3764065b21144913df7515d52e228c09427a004afe9c1a16b0"}, @@ -31,8 +31,9 @@ "req": {:hex, :req, "0.5.6", "8fe1eead4a085510fe3d51ad854ca8f20a622aae46e97b302f499dfb84f726ac", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.17", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "cfaa8e720945d46654853de39d368f40362c2641c4b2153c886418914b372185"}, "req_athena": {:hex, :req_athena, "0.2.0", "a88b1500105f7dfade0c6fdc28174577c72ae6d96f8ab67c5a5cb594f68c8b10", [:mix], [{:aws_credentials, "~> 0.2", [hex: :aws_credentials, repo: "hexpm", optional: true]}, {:aws_signature, "~> 0.3.0", [hex: :aws_signature, repo: "hexpm", optional: false]}, {:explorer, "~> 0.9", [hex: :explorer, repo: "hexpm", optional: true]}, {:req, "~> 0.5.0", [hex: :req, repo: "hexpm", optional: false]}, {:req_s3, "~> 0.2", [hex: :req_s3, repo: "hexpm", optional: false]}], "hexpm", "75376f2f7b6fa924b51cb7d797287a1967589ae7d7d355c50e4170aa7f750d3c"}, "req_bigquery": {:hex, :req_bigquery, "0.1.4", "4e1cbadb773d7272ef6c5ed5930f3f2d5df82bc0c6966f00ee71fa681e43a8c2", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:goth, "~> 1.3", [hex: :goth, repo: "hexpm", optional: false]}, {:req, "~> 0.3.5 or ~> 0.4", [hex: :req, repo: "hexpm", optional: false]}, {:table, "~> 0.1.1", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "9d099fbaca9eb89909d955ce7ff3dcc731f54e75bf68f99c97bbc2dbeef83ff6"}, + "req_ch": {:git, "https://github.com/livebook-dev/req_ch.git", "5246d18497e32e6b96152333f6ca85b6aa04ff22", [branch: "ps-add-query-4"]}, "req_s3": {:hex, :req_s3, "0.2.3", "ede5f4c792cf39995379307733ff4593032a876f38da29d9d7ea03881b498b51", [:mix], [{:req, "~> 0.5.6", [hex: :req, repo: "hexpm", optional: false]}], "hexpm", "31b5d52490495c8aeea7e3c5cbcec82f49035e11bdaf41f0e58ab716fefe44ca"}, - "rustler_precompiled": {:hex, :rustler_precompiled, "0.8.1", "8afe0b6f3a9a677ada046cdd23e3f4c6399618b91a6122289324774961281e1e", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "90b8c2297bf7959cfa1c927b2881faad7bb0707183124955369991b76177a166"}, + "rustler_precompiled": {:hex, :rustler_precompiled, "0.8.2", "5f25cbe220a8fac3e7ad62e6f950fcdca5a5a5f8501835d2823e8c74bf4268d5", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "63d1bd5f8e23096d1ff851839923162096364bac8656a4a3c00d1fff8e83ee0a"}, "table": {:hex, :table, "0.1.2", "87ad1125f5b70c5dea0307aa633194083eb5182ec537efc94e96af08937e14a8", [:mix], [], "hexpm", "7e99bc7efef806315c7e65640724bf165c3061cdc5d854060f74468367065029"}, "table_rex": {:hex, :table_rex, "4.0.0", "3c613a68ebdc6d4d1e731bc973c233500974ec3993c99fcdabb210407b90959b", [:mix], [], "hexpm", "c35c4d5612ca49ebb0344ea10387da4d2afe278387d4019e4d8111e815df8f55"}, "tds": {:hex, :tds, "2.3.4", "534749dd9ef61af960fcafa9cbb7186d6d7b9f92ea0133fb25da07b121c8295c", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "bb9a53d4688a85fd566f342f76b50d39adfc4b410062886ef908365ead24ba3f"}, diff --git a/test/kino_db/connection_cell_test.exs b/test/kino_db/connection_cell_test.exs index 0db2c0b..a3586dc 100644 --- a/test/kino_db/connection_cell_test.exs +++ b/test/kino_db/connection_cell_test.exs @@ -209,16 +209,14 @@ defmodule KinoDB.ConnectionCellTest do ''' assert ConnectionCell.to_source(put_in(attrs["type"], "clickhouse")) == ~s''' - opts = [ - hostname: "localhost", - port: 4444, - username: "admin", - password: "pass", - database: "default", - scheme: "http" - ] + conn = + ReqCH.new( + database: "default", + auth: {:basic, "admin:pass"}, + base_url: "http://localhost:4444" + ) - {:ok, conn} = Kino.start_child({Ch, opts})\ + :ok\ ''' end diff --git a/test/kino_db/sql_cell_test.exs b/test/kino_db/sql_cell_test.exs index 4044f38..c519715 100644 --- a/test/kino_db/sql_cell_test.exs +++ b/test/kino_db/sql_cell_test.exs @@ -123,7 +123,7 @@ defmodule KinoDB.SQLCellTest do """ assert SQLCell.to_source(put_in(attrs["connection"]["type"], "clickhouse")) == """ - result = Ch.query!(conn, ~S"SELECT id FROM users", [])\ + result = ReqCH.query!(conn, ~S"SELECT id FROM users", [], format: :explorer).body\ """ assert SQLCell.to_source(put_in(attrs["connection"]["type"], "sqlserver")) == """ @@ -212,14 +212,15 @@ defmodule KinoDB.SQLCellTest do assert SQLCell.to_source(put_in(attrs["connection"]["type"], "clickhouse")) == ~s''' result = - Ch.query!( + ReqCH.query!( conn, ~S""" SELECT id FROM users WHERE last_name = 'Sherlock' """, - [] - )\ + [], + format: :explorer + ).body\ ''' assert SQLCell.to_source(put_in(attrs["connection"]["type"], "sqlserver")) == ~s''' @@ -295,11 +296,12 @@ defmodule KinoDB.SQLCellTest do assert SQLCell.to_source(put_in(attrs["connection"]["type"], "clickhouse")) == ~s''' result = - Ch.query!( + ReqCH.query!( conn, - ~S"SELECT id FROM users WHERE id {$1:String} AND name LIKE {$2:String}", - [user_id, search <> \"%\"] - )\ + ~S"SELECT id FROM users WHERE id {user_id:String} AND name LIKE {param_2:String}", + [{"user_id", user_id}, {"param_2", search <> \"%\"}], + format: :explorer + ).body\ ''' assert SQLCell.to_source(put_in(attrs["connection"]["type"], "sqlserver")) == ~s''' @@ -402,15 +404,16 @@ defmodule KinoDB.SQLCellTest do assert SQLCell.to_source(put_in(attrs["connection"]["type"], "clickhouse")) == ~s''' result = - Ch.query!( + ReqCH.query!( conn, ~S""" SELECT id from users -- WHERE id = {{user_id1}} - /* WHERE id = {{user_id2}} */ WHERE id = {$1:String} + /* WHERE id = {{user_id2}} */ WHERE id = {user_id3:String} """, - [user_id3] - )\ + [{"user_id3", user_id3}], + format: :explorer + ).body\ ''' assert SQLCell.to_source(put_in(attrs["connection"]["type"], "sqlserver")) == ~s''' @@ -461,7 +464,7 @@ defmodule KinoDB.SQLCellTest do """ assert SQLCell.to_source(put_in(attrs["connection"]["type"], "clickhouse")) == """ - result = Ch.query!(conn, ~S"SELECT id FROM users", [])\ + result = ReqCH.query!(conn, ~S"SELECT id FROM users", [], format: :explorer).body\ """ assert SQLCell.to_source(put_in(attrs["connection"]["type"], "sqlserver")) == """ @@ -495,7 +498,7 @@ defmodule KinoDB.SQLCellTest do """ assert SQLCell.to_source(put_in(attrs["connection"]["type"], "clickhouse")) == """ - result = Ch.query!(conn, ~S"SELECT id FROM users", [])\ + result = ReqCH.query!(conn, ~S"SELECT id FROM users", [], format: :explorer).body\ """ assert SQLCell.to_source(put_in(attrs["connection"]["type"], "bigquery")) == """