diff --git a/autoload/db_ui.vim b/autoload/db_ui.vim index 6971c7a..7444db7 100644 --- a/autoload/db_ui.vim +++ b/autoload/db_ui.vim @@ -232,13 +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') let db = { \ 'url': a:db.url, \ 'conn': '', diff --git a/autoload/db_ui/schemas.vim b/autoload/db_ui/schemas.vim index 81732d8..7e2dad8 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 @@ -105,6 +105,17 @@ 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, + \ } + let s:oracle_args = join( \ [ \ 'SET linesize 4000', @@ -214,6 +225,7 @@ let s:schemas = { \ 'postgresql': s:postgresql, \ 'sqlserver': s:sqlserver, \ 'mysql': s:mysql, + \ 'cassandra': s:cassandra, \ 'mariadb': s:mysql, \ 'oracle': s:oracle, \ 'bigquery': s:bigquery, diff --git a/autoload/db_ui/table_helpers.vim b/autoload/db_ui/table_helpers.vim index 14c3c18..834204d 100644 --- a/autoload/db_ui/table_helpers.vim +++ b/autoload/db_ui/table_helpers.vim @@ -40,6 +40,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 @@ -186,6 +192,7 @@ let s:helpers = { \ 'bigquery': s:bigquery, \ 'postgresql': s:postgres, \ 'mysql': s:mysql, + \ 'cassandra': s:cassandra, \ 'mariadb': s:mysql, \ 'oracle': s:oracle, \ 'sqlite': s:sqlite,