-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b6635d
commit 2794a46
Showing
8 changed files
with
627 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
defmodule Sanbase.Clickhouse.Autocomplete do | ||
alias Sanbase.ClickhouseRepo | ||
|
||
def get_data() do | ||
Sanbase.ClickhouseRepo.put_dynamic_repo(Sanbase.ClickhouseRepo.ReadOnly) | ||
|
||
result = %{ | ||
columns: get_columns(), | ||
functions: get_functions(), | ||
tables: get_tables() | ||
} | ||
|
||
{:ok, result} | ||
end | ||
|
||
defp get_tables() do | ||
sql = """ | ||
SELECT name, engine, partition_key, sorting_key, primary_key | ||
FROM system.tables | ||
WHERE database = 'default' | ||
""" | ||
|
||
query_struct = Sanbase.Clickhouse.Query.new(sql, %{}) | ||
|
||
{:ok, result} = | ||
ClickhouseRepo.query_transform( | ||
query_struct, | ||
fn [ | ||
name, | ||
engine, | ||
partition_key, | ||
sorting_key, | ||
primary_key | ||
] -> | ||
%{ | ||
name: name, | ||
engine: engine, | ||
partition_key: partition_key, | ||
sorting_key: sorting_key, | ||
primary_key: primary_key | ||
} | ||
end | ||
) | ||
|
||
result | ||
end | ||
|
||
defp get_columns() do | ||
sql = """ | ||
SELECT table, name, type, is_in_partition_key, is_in_sorting_key, is_in_primary_key | ||
FROM system.columns | ||
WHERE database = 'default' | ||
""" | ||
|
||
query_struct = Sanbase.Clickhouse.Query.new(sql, %{}) | ||
|
||
{:ok, result} = | ||
ClickhouseRepo.query_transform( | ||
query_struct, | ||
fn [ | ||
table, | ||
name, | ||
type, | ||
is_in_partition_key, | ||
is_in_sorting_key, | ||
is_in_primary_key | ||
] -> | ||
%{ | ||
table: table, | ||
name: name, | ||
type: type, | ||
is_in_partition_key: is_in_partition_key == 1, | ||
is_in_sorting_key: is_in_sorting_key == 1, | ||
is_in_primary_key: is_in_primary_key == 1 | ||
} | ||
end | ||
) | ||
|
||
result | ||
end | ||
|
||
defp get_functions() do | ||
sql = """ | ||
SELECT name | ||
FROM system.functions | ||
""" | ||
|
||
query_struct = Sanbase.Clickhouse.Query.new(sql, %{}) | ||
{:ok, result} = ClickhouseRepo.query_transform(query_struct, fn [name] -> %{name: name} end) | ||
result | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.