Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cassandra Support #215

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion autoload/db_ui.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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': '',
Expand Down
16 changes: 14 additions & 2 deletions autoload/db_ui/schemas.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions autoload/db_ui/table_helpers.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down