From b1183072926dd758ed5001f79210bf3c725ea182 Mon Sep 17 00:00:00 2001 From: ViSHNUPrABU Date: Tue, 26 Dec 2023 23:12:18 +0530 Subject: [PATCH 1/3] Cassandra adapter added and trimming & empty-checking the results instead of empty-trim-checking --- autoload/db_ui.vim | 2 +- autoload/db_ui/schemas.vim | 17 +++++++++++++++-- autoload/db_ui/table_helpers.vim | 7 +++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/autoload/db_ui.vim b/autoload/db_ui.vim index 67db6dc..21e9059 100644 --- a/autoload/db_ui.vim +++ b/autoload/db_ui.vim @@ -240,7 +240,7 @@ function! s:dbui.generate_new_db_entry(db) abort let scheme_info = db_ui#schemas#get(scheme) let buffers = filter(copy(self.old_buffers), 'fnamemodify(v:val, ":e") =~? "^".a:db.name."-" || fnamemodify(v:val, ":t") =~? "^".a:db.name."-"') let schema_support = !empty(get(scheme_info, 'schemes_query', 0)) - if schema_support && tolower(scheme) ==? 'mysql' && parsed_url.path !=? '/' + if schema_support && (tolower(scheme) ==? 'mysql' || tolower(scheme) ==? 'cassandra') && parsed_url.path !=? '/' let schema_support = 0 endif let filetype = get(scheme_info, 'filetype', 'sql') diff --git a/autoload/db_ui/schemas.vim b/autoload/db_ui/schemas.vim index a1b057b..2a294f4 100644 --- a/autoload/db_ui/schemas.vim +++ b/autoload/db_ui/schemas.vim @@ -4,9 +4,9 @@ endfunction function! s:results_parser(results, delimiter, min_len) abort if a:min_len ==? 1 - return filter(a:results, '!empty(trim(v:val))') + return filter(map(a:results, 'trim(v:val)'), '!empty(v:val)') endif - let mapped = map(a:results, {_,row -> filter(split(row, a:delimiter), '!empty(trim(v:val))')}) + let mapped = map(a:results, {_,row -> filter(map(split(row, a:delimiter), 'trim(v:val)'), '!empty(v:val)')}) if a:min_len > 1 return filter(mapped, 'len(v:val) ==? '.a:min_len) endif @@ -98,6 +98,18 @@ let s:mysql = { \ 'filetype': 'mysql', \ } +let s:cassandra = { + \ 'schemes_query': 'SELECT keyspace_name FROM system_schema.keyspaces;', + \ 'schemes_tables_query': 'SELECT keyspace_name, table_name FROM system_schema.tables;', + \ 'cell_line_number': 3, + \ 'cell_line_pattern': '^-\++-\+', + \ 'requires_stdin': v:true, + \ 'parse_results': {results, min_len -> s:results_parser(results[3:-2], '|', min_len)}, + \ 'default_scheme': '', + \ 'quote': 0, + \ 'filetype': 'cql', + \ } + let s:oracle_args = join( \ [ \ 'SET linesize 4000', @@ -177,6 +189,7 @@ let s:schemas = { \ 'postgresql': s:postgresql, \ 'sqlserver': s:sqlserver, \ 'mysql': s:mysql, + \ 'cassandra': s:cassandra, \ 'oracle': s:oracle, \ 'bigquery': s:bigquery, \ } diff --git a/autoload/db_ui/table_helpers.vim b/autoload/db_ui/table_helpers.vim index e4a1c2d..5f68286 100644 --- a/autoload/db_ui/table_helpers.vim +++ b/autoload/db_ui/table_helpers.vim @@ -39,6 +39,12 @@ let s:mysql = { \ 'Primary Keys': "SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_SCHEMA = '{schema}' AND TABLE_NAME = '{table}' AND CONSTRAINT_TYPE = 'PRIMARY KEY'", \ } +let s:cassandra = { + \ 'List': 'SELECT * from {optional_schema}{table} LIMIT 200;', + \ 'Columns': "SELECT * FROM system_schema.columns WHERE keyspace_name='{dbname}' AND table_name='{table}';", + \ 'Indexes': "SELECT * FROM system_schema.indexes WHERE keyspace_name='{dbname}' AND table_name='{table}';", + \ } + let s:oracle_from = " \FROM all_constraints N\n \JOIN all_cons_columns L\n\t @@ -185,6 +191,7 @@ let s:helpers = { \ 'bigquery': s:bigquery, \ 'postgresql': s:postgres, \ 'mysql': s:mysql, + \ 'cassandra': s:cassandra, \ 'oracle': s:oracle, \ 'sqlite': s:sqlite, \ 'sqlserver': s:sqlserver, From d6b258f663d48ab81fb1b2ed27c60febc3d23605 Mon Sep 17 00:00:00 2001 From: ViSHNUPrABU Date: Wed, 27 Dec 2023 22:25:39 +0530 Subject: [PATCH 2/3] Removing filetype cql for Cassandra bcaz of no support for cql in coc-db --- autoload/db_ui/schemas.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/autoload/db_ui/schemas.vim b/autoload/db_ui/schemas.vim index 2a294f4..0a9e453 100644 --- a/autoload/db_ui/schemas.vim +++ b/autoload/db_ui/schemas.vim @@ -107,7 +107,6 @@ let s:cassandra = { \ 'parse_results': {results, min_len -> s:results_parser(results[3:-2], '|', min_len)}, \ 'default_scheme': '', \ 'quote': 0, - \ 'filetype': 'cql', \ } let s:oracle_args = join( From 541444991eea9751bd8f115997cd354109f87979 Mon Sep 17 00:00:00 2001 From: "vishnu.prabu" Date: Mon, 15 Jul 2024 07:50:46 +0530 Subject: [PATCH 3/3] dbui not opening issue fix --- autoload/db_ui.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/db_ui.vim b/autoload/db_ui.vim index e9f15b2..7444db7 100644 --- a/autoload/db_ui.vim +++ b/autoload/db_ui.vim @@ -232,19 +232,19 @@ function! s:dbui.generate_new_db_entry(db) abort if empty(parsed_url) return parsed_url endif + let scheme = get(parsed_url, 'scheme', '') let db_name = substitute(get(parsed_url, 'path', ''), '^\/', '', '') let save_path = '' if !empty(self.save_path) let save_path = printf('%s/%s', self.save_path, a:db.name) endif + let scheme_info = db_ui#schemas#get(scheme) let buffers = filter(copy(self.old_buffers), 'fnamemodify(v:val, ":e") =~? "^".a:db.name."-" || fnamemodify(v:val, ":t") =~? "^".a:db.name."-"') let schema_support = !empty(get(scheme_info, 'schemes_query', 0)) if schema_support && (tolower(scheme) ==? 'mysql' || tolower(scheme) ==? 'cassandra') && parsed_url.path !=? '/' let schema_support = 0 endif let filetype = get(scheme_info, 'filetype', 'sql') - return { - let db = { \ 'url': a:db.url, \ 'conn': '',