From e3a43d706b5a34b85830539fbb054b84b3822c87 Mon Sep 17 00:00:00 2001 From: ViSHNUPrABU Date: Tue, 26 Dec 2023 23:15:47 +0530 Subject: [PATCH 1/4] Cassandra support for auto-completion added --- autoload/vim_dadbod_completion.vim | 2 +- autoload/vim_dadbod_completion/compe.vim | 2 +- autoload/vim_dadbod_completion/schemas.vim | 14 ++++++++++++++ package.json | 2 +- plugin/vim_dadbod_completion.vim | 2 +- .../deoplete/source/vim_dadbod_completion.py | 2 +- src/index.js | 2 +- 7 files changed, 20 insertions(+), 6 deletions(-) diff --git a/autoload/vim_dadbod_completion.vim b/autoload/vim_dadbod_completion.vim index 2c43204..c000fa8 100644 --- a/autoload/vim_dadbod_completion.vim +++ b/autoload/vim_dadbod_completion.vim @@ -1,6 +1,6 @@ let s:cache = {} let s:buffers = {} -let s:filetypes = ['sql', 'mysql', 'plsql'] +let s:filetypes = ['sql', 'mysql', 'plsql', 'cql'] let s:quotes = vim_dadbod_completion#schemas#get_quotes_rgx() let s:trigger_rgx = printf('\(%s\|\.\)$', s:quotes.open) diff --git a/autoload/vim_dadbod_completion/compe.vim b/autoload/vim_dadbod_completion/compe.vim index 2ffac84..ebbd479 100644 --- a/autoload/vim_dadbod_completion/compe.vim +++ b/autoload/vim_dadbod_completion/compe.vim @@ -11,7 +11,7 @@ function! vim_dadbod_completion#compe#create() abort endfunction function! s:get_metadata(...) abort - return { 'filetypes': ['sql', 'mysql', 'plsql'], 'priority': 100, 'dup': 0 } + return { 'filetypes': ['sql', 'mysql', 'plsql', 'cql'], 'priority': 100, 'dup': 0 } endfunction function! s:determine(context) abort diff --git a/autoload/vim_dadbod_completion/schemas.vim b/autoload/vim_dadbod_completion/schemas.vim index c5e31b1..668d749 100644 --- a/autoload/vim_dadbod_completion/schemas.vim +++ b/autoload/vim_dadbod_completion/schemas.vim @@ -68,6 +68,19 @@ let s:oracle = { \ 'table_column_query': {table -> printf(s:oracle_base_column_query, "AND C.table_name='".table."'")}, \ } +let s:cassandra = { +\ 'column_parser': function('s:map_and_filter', ['|']), +\ 'column_query': "SELECT table_name, column_name FROM system_schema.columns;", +\ 'count_column_query': "SELECT COUNT(*) FROM system_schema.columns;", +\ 'count_parser': function('s:count_parser', [1]), +\ 'table_column_query': {table -> substitute("SELECT table_name, column_name FROM system_schema.columns WHERE table_name='{db_tbl_name}';", '{db_tbl_name}', "'".table."'", '')}, +\ 'schemas_query': "SELECT keyspace_name, table_name FROM system_schema.columns GROUP BY keyspace_name,table_name;", +\ 'schemas_parser': function('s:map_and_filter', ['|']), +\ 'requires_stdin': v:true, +\ 'quote': ['"', '"'], +\ 'should_quote': function('s:should_quote', [['reserved_word', 'space']]), +\ } + let s:schemas = { \ 'postgres': s:postgres, \ 'postgresql': s:postgres, @@ -84,6 +97,7 @@ let s:schemas = { \ 'count_parser': function('s:count_parser', [1]) \ }, \ 'oracle': s:oracle, + \ 'cassandra': s:cassandra, \ 'sqlite': { \ 'args': ['-list'], \ 'column_query': "SELECT m.name AS table_name, ii.name AS column_name FROM sqlite_schema AS m, pragma_table_list(m.name) AS il, pragma_table_info(il.name) AS ii WHERE m.type='table' ORDER BY column_name ASC;", diff --git a/package.json b/package.json index 6e552ad..66d5b72 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "coc.source.db.filetypes": { "type": ["array"], - "default": ["sql", "mysql", "plsql"], + "default": ["sql", "mysql", "plsql", "cql"], "items": { "type": "string" } diff --git a/plugin/vim_dadbod_completion.vim b/plugin/vim_dadbod_completion.vim index a95ce9b..2c44b2b 100644 --- a/plugin/vim_dadbod_completion.vim +++ b/plugin/vim_dadbod_completion.vim @@ -6,7 +6,7 @@ let g:vim_dadbod_completion_loaded = 1 augroup vim_dadbod_completion autocmd! - autocmd FileType sql,mysql,plsql call vim_dadbod_completion#fetch(str2nr(expand(''))) + autocmd FileType sql,mysql,plsql,cql call vim_dadbod_completion#fetch(str2nr(expand(''))) augroup END command DBCompletionClearCache call vim_dadbod_completion#clear_cache() diff --git a/rplugin/python3/deoplete/source/vim_dadbod_completion.py b/rplugin/python3/deoplete/source/vim_dadbod_completion.py index ef8e433..1f6fe25 100644 --- a/rplugin/python3/deoplete/source/vim_dadbod_completion.py +++ b/rplugin/python3/deoplete/source/vim_dadbod_completion.py @@ -6,7 +6,7 @@ def __init__(self, vim): Base.__init__(self, vim) self.name = 'vim-dadbod-completion' self.mark = '' - self.filetypes = ['sql', 'mysql', 'plsql'] + self.filetypes = ['sql', 'mysql', 'plsql', 'cql'] self.input_pattern = '\w+|\.|"|\[|`' self.rank = 500 self.max_pattern_length = -1 diff --git a/src/index.js b/src/index.js index a1f6c8c..f2ea1a0 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ const { sources, workspace } = require('coc.nvim'); const { nvim } = workspace; const path = require('path'); const rtpPath = path.resolve(__dirname, '../'); -const validFiletypes = ['sql', 'mysql', 'plsql'] +const validFiletypes = ['sql', 'mysql', 'plsql', 'cql'] exports.activate = async (context) => { From e81f23beb82f61745f3645a7b779af58587a0443 Mon Sep 17 00:00:00 2001 From: ViSHNUPrABU Date: Wed, 27 Dec 2023 22:20:44 +0530 Subject: [PATCH 2/4] Reverting cql as there is no support for cql in coc-db yet --- autoload/vim_dadbod_completion.vim | 2 +- autoload/vim_dadbod_completion/compe.vim | 2 +- package.json | 2 +- plugin/vim_dadbod_completion.vim | 2 +- rplugin/python3/deoplete/source/vim_dadbod_completion.py | 2 +- src/index.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/autoload/vim_dadbod_completion.vim b/autoload/vim_dadbod_completion.vim index c000fa8..2c43204 100644 --- a/autoload/vim_dadbod_completion.vim +++ b/autoload/vim_dadbod_completion.vim @@ -1,6 +1,6 @@ let s:cache = {} let s:buffers = {} -let s:filetypes = ['sql', 'mysql', 'plsql', 'cql'] +let s:filetypes = ['sql', 'mysql', 'plsql'] let s:quotes = vim_dadbod_completion#schemas#get_quotes_rgx() let s:trigger_rgx = printf('\(%s\|\.\)$', s:quotes.open) diff --git a/autoload/vim_dadbod_completion/compe.vim b/autoload/vim_dadbod_completion/compe.vim index ebbd479..2ffac84 100644 --- a/autoload/vim_dadbod_completion/compe.vim +++ b/autoload/vim_dadbod_completion/compe.vim @@ -11,7 +11,7 @@ function! vim_dadbod_completion#compe#create() abort endfunction function! s:get_metadata(...) abort - return { 'filetypes': ['sql', 'mysql', 'plsql', 'cql'], 'priority': 100, 'dup': 0 } + return { 'filetypes': ['sql', 'mysql', 'plsql'], 'priority': 100, 'dup': 0 } endfunction function! s:determine(context) abort diff --git a/package.json b/package.json index 66d5b72..6e552ad 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "coc.source.db.filetypes": { "type": ["array"], - "default": ["sql", "mysql", "plsql", "cql"], + "default": ["sql", "mysql", "plsql"], "items": { "type": "string" } diff --git a/plugin/vim_dadbod_completion.vim b/plugin/vim_dadbod_completion.vim index 2c44b2b..a95ce9b 100644 --- a/plugin/vim_dadbod_completion.vim +++ b/plugin/vim_dadbod_completion.vim @@ -6,7 +6,7 @@ let g:vim_dadbod_completion_loaded = 1 augroup vim_dadbod_completion autocmd! - autocmd FileType sql,mysql,plsql,cql call vim_dadbod_completion#fetch(str2nr(expand(''))) + autocmd FileType sql,mysql,plsql call vim_dadbod_completion#fetch(str2nr(expand(''))) augroup END command DBCompletionClearCache call vim_dadbod_completion#clear_cache() diff --git a/rplugin/python3/deoplete/source/vim_dadbod_completion.py b/rplugin/python3/deoplete/source/vim_dadbod_completion.py index 1f6fe25..ef8e433 100644 --- a/rplugin/python3/deoplete/source/vim_dadbod_completion.py +++ b/rplugin/python3/deoplete/source/vim_dadbod_completion.py @@ -6,7 +6,7 @@ def __init__(self, vim): Base.__init__(self, vim) self.name = 'vim-dadbod-completion' self.mark = '' - self.filetypes = ['sql', 'mysql', 'plsql', 'cql'] + self.filetypes = ['sql', 'mysql', 'plsql'] self.input_pattern = '\w+|\.|"|\[|`' self.rank = 500 self.max_pattern_length = -1 diff --git a/src/index.js b/src/index.js index f2ea1a0..a1f6c8c 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ const { sources, workspace } = require('coc.nvim'); const { nvim } = workspace; const path = require('path'); const rtpPath = path.resolve(__dirname, '../'); -const validFiletypes = ['sql', 'mysql', 'plsql', 'cql'] +const validFiletypes = ['sql', 'mysql', 'plsql'] exports.activate = async (context) => { From 6aa405255cc99de82fcf2683cc3128872bc5424c Mon Sep 17 00:00:00 2001 From: ViSHNUPrABU Date: Wed, 27 Dec 2023 22:31:42 +0530 Subject: [PATCH 3/4] Adding Cassandra in doc --- README.md | 2 +- doc/vim-dadbod-completion.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1acac86..5a8ba18 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ let g:completion_matching_ignore_case = 1 ## Features * Autocomplete table names, with automatic quoting where needed. Works for all schemes that [vim-dadbod](https://github.com/tpope/vim-dadbod) supports. -* Autocomplete table columns, context aware. Also knows to read aliases (`select * from mytable tbl where tbl.id = 1`). Currently works for `PostgreSQL`, `MySQL`, `Oracle`, `SQLite` (requires version `3.37.0 (2021-11-27)`) and `SQLserver/MSSQL`. +* Autocomplete table columns, context aware. Also knows to read aliases (`select * from mytable tbl where tbl.id = 1`). Currently works for `PostgreSQL`, `MySQL`, `Cassandra`, `Oracle`, `SQLite` (requires version `3.37.0 (2021-11-27)`) and `SQLserver/MSSQL`. * Out of the box integration with [vim-dadbod-ui](https://github.com/kristijanhusak/vim-dadbod-ui) ## How it works diff --git a/doc/vim-dadbod-completion.txt b/doc/vim-dadbod-completion.txt index d09648d..fa14341 100755 --- a/doc/vim-dadbod-completion.txt +++ b/doc/vim-dadbod-completion.txt @@ -86,7 +86,7 @@ For `deoplete`, `completion-nvim`, `nvim-compe`, `ddc` and `omnifunc`, install i FEATURES *vim-dadbod-completion-features* * Autocomplete table names, with automatic quoting where needed. Works for all schemes that vim-dadbod (https://github.com/tpope/vim-dadbod) supports. -* Autocomplete table columns, context aware. Also knows to read aliases (). Currently works for `PostgreSQL`, `MySQL`, `Oracle`, `SQLite` (requires version `3.37.0 (2021-11-27)`) and `SQLserver/MSSQL`. +* Autocomplete table columns, context aware. Also knows to read aliases (). Currently works for `PostgreSQL`, `MySQL`, `Cassandra`, `Oracle`, `SQLite` (requires version `3.37.0 (2021-11-27)`) and `SQLserver/MSSQL`. * Out of the box integration with vim-dadbod-ui (https://github.com/kristijanhusak/vim-dadbod-ui) -------------------------------------------------------------------------------- From eea0d54fbd3641d011a1f1680c37c5ba810c2870 Mon Sep 17 00:00:00 2001 From: "vishnu.prabu" Date: Mon, 19 Aug 2024 14:59:33 +0530 Subject: [PATCH 4/4] missing braces added --- autoload/vim_dadbod_completion/schemas.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/vim_dadbod_completion/schemas.vim b/autoload/vim_dadbod_completion/schemas.vim index 6bff236..a6755b0 100644 --- a/autoload/vim_dadbod_completion/schemas.vim +++ b/autoload/vim_dadbod_completion/schemas.vim @@ -83,6 +83,7 @@ let s:cassandra = { \ 'requires_stdin': v:true, \ 'quote': ['"', '"'], \ 'should_quote': function('s:should_quote', [['reserved_word', 'space']]), +\ } let s:mysql = { \ 'column_query': s:query,