Skip to content

Commit

Permalink
Merge pull request #304 from CezaryPukownik/clickhouse-support
Browse files Browse the repository at this point in the history
Add support for Clickhouse
  • Loading branch information
kristijanhusak authored Jan 29, 2025
2 parents 65454e2 + 5398299 commit f4d37b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions autoload/db_ui/schemas.vim
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,28 @@ let s:bigquery = {
\ }


let s:clickhouse_schemes_query = "
\ SELECT name as schema_name
\ FROM system.databases
\ ORDER BY name"

let s:clickhouse_schemes_tables_query = "
\ SELECT database AS table_schema, name AS table_name
\ FROM system.tables
\ ORDER BY table_name"

let s:clickhouse = {
\ 'args': ['-q'],
\ 'schemes_query': trim(s:clickhouse_schemes_query),
\ 'schemes_tables_query': trim(s:clickhouse_schemes_tables_query),
\ 'cell_line_number': 1,
\ 'cell_line_pattern': '^.*$',
\ 'parse_results': {results, min_len -> s:results_parser(results, '\t', min_len)},
\ 'default_scheme': '',
\ 'quote': 1,
\ }

" Add ClickHouse to the schemas dictionary
let s:schemas = {
\ 'postgres': s:postgresql,
\ 'postgresql': s:postgresql,
Expand All @@ -218,8 +240,10 @@ let s:schemas = {
\ 'mariadb': s:mysql,
\ 'oracle': s:oracle,
\ 'bigquery': s:bigquery,
\ 'clickhouse': s:clickhouse,
\ }


if !exists('g:db_adapter_postgres')
let g:db_adapter_postgres = 'db#adapter#postgresql#'
endif
Expand Down
6 changes: 6 additions & 0 deletions autoload/db_ui/table_helpers.vim
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ let s:sqlserver = {
\ 'Describe': 'exec sp_help ''{schema}.{table}''',
\ }

let s:clickhouse = {
\ 'List': "select * from `{schema}`.`{table}` limit 100 Format PrettyCompactMonoBlock",
\ 'Columns': "select name from system.columns where database='{schema} and table={table}'",
\ }

let s:helpers = {
\ 'bigquery': s:bigquery,
\ 'postgresql': s:postgres,
Expand All @@ -190,6 +195,7 @@ let s:helpers = {
\ 'oracle': s:oracle,
\ 'sqlite': s:sqlite,
\ 'sqlserver': s:sqlserver,
\ 'clickhouse': s:clickhouse,
\ 'mongodb': { 'List': '{table}.find()'},
\ }

Expand Down

0 comments on commit f4d37b7

Please sign in to comment.