From f8cf5bc91d0fa80af4dff716bb6070206b544e89 Mon Sep 17 00:00:00 2001 From: Samuel Abreu Date: Sun, 31 Mar 2024 18:10:21 -0300 Subject: [PATCH 1/4] Add support for AWS dynamodb Using url params to set profile and endpoint url if needed. --- README.markdown | 9 +++++++ autoload/db/adapter/dynamodb.vim | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 autoload/db/adapter/dynamodb.vim diff --git a/README.markdown b/README.markdown index 2130598..175f7e9 100644 --- a/README.markdown +++ b/README.markdown @@ -10,6 +10,7 @@ take on [dbext.vim][], improving on it on the following ways: * Supports a modern array of backends, including NoSQL databases: - Big Query - ClickHouse + - DynamoDB - Impala - jq - MongoDB @@ -47,6 +48,13 @@ to pass to the database. Results are displayed in a preview window. :DB sqlite:myfile.sqlite3 select count(*) from widgets :DB redis:/// CLIENT LIST +DynamoDB uses profiles [Configuration and credential file settings][] as +authentication + +* :DB dynamodb:// # use default profile +* :DB dynamodb://profile_name +* :DB dynamodb://profile_name@localhost:8888 # To connect on a local dynamodb instance + Give a range to run part or all of the current buffer as a query. :%DB mysql://root@localhost/bazquux @@ -79,6 +87,7 @@ try [dadbod-ui][]. [heroku.vim]: https://tpope.io/vim/heroku.git [rails.vim]: https://tpope.io/vim/rails.git [dadbod-ui]: https://github.com/kristijanhusak/vim-dadbod-ui +[Configuration and credential file settings]: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html ## Installation diff --git a/autoload/db/adapter/dynamodb.vim b/autoload/db/adapter/dynamodb.vim new file mode 100644 index 0000000..b42bebe --- /dev/null +++ b/autoload/db/adapter/dynamodb.vim @@ -0,0 +1,43 @@ +function! s:command(url, output) abort + let url = db#url#parse(a:url) + let endpoint_url = [] + if has_key(url, 'user') + let profile = url.user + let http_url = 'http://' .. url.host .. ':' .. url.port + let endpoint_url = ['--endpoint-url', http_url] + else + if has_key(url, 'host') + let profile = url.host + else + let profile = 'default' + endif + endif + return ['aws', 'dynamodb', '--profile', profile, '--output', a:output] + endpoint_url +endfunction + +function! db#adapter#dynamodb#input_extension() abort + return 'js' +endfunction + +function! db#adapter#dynamodb#output_extension() abort + return 'json' +endfunction + +function! db#adapter#dynamodb#input(url, in) abort + if filereadable(a:in) + let lines = readfile(a:in) + return s:command(a:url, 'json') + split(lines[0]) + endif + return ['echo', 'no', 'command'] +endfunction + +function! db#adapter#dynamodb#auth_input() abort + return v:false +endfunction + +function! db#adapter#dynamodb#tables(url) abort + let cmd = s:command(a:url, 'text') + ['list-tables'] + let out = db#systemlist(cmd) + return map(out, 'matchstr(v:val, "\\w*$")') +endfunction + From feedb136e55b5c4cfee3c5ed1b406eca719ecbdb Mon Sep 17 00:00:00 2001 From: Samuel Abreu Date: Mon, 1 Apr 2024 08:17:48 -0300 Subject: [PATCH 2/4] Move dynamodb usage examples to doc --- README.markdown | 7 ------- doc/dadbod.txt | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.markdown b/README.markdown index 175f7e9..0aefe11 100644 --- a/README.markdown +++ b/README.markdown @@ -48,13 +48,6 @@ to pass to the database. Results are displayed in a preview window. :DB sqlite:myfile.sqlite3 select count(*) from widgets :DB redis:/// CLIENT LIST -DynamoDB uses profiles [Configuration and credential file settings][] as -authentication - -* :DB dynamodb:// # use default profile -* :DB dynamodb://profile_name -* :DB dynamodb://profile_name@localhost:8888 # To connect on a local dynamodb instance - Give a range to run part or all of the current buffer as a query. :%DB mysql://root@localhost/bazquux diff --git a/doc/dadbod.txt b/doc/dadbod.txt index a6f6acf..655aab2 100644 --- a/doc/dadbod.txt +++ b/doc/dadbod.txt @@ -108,6 +108,20 @@ ClickHouse ~ < Use the `secure` query parameter to enable TLS. + *dadbod-dynamodb* +DynamoDB ~ +> + dynamodb://[@[host:port]] + dynamodb://[] + dynamodb:// +< + +Use @host:port to use on a local dynamodb instance, for real AWS +DynamoDB don't set any host and port. + +Use any AWS credential file accepted by `aws` cli by profile_name +or environment variables before launching vim. + *dadbod-impala* Impala ~ > From 2ff84f9c0fd603b11fb1435a8aad68ef716861af Mon Sep 17 00:00:00 2001 From: Samuel Abreu Date: Mon, 1 Apr 2024 08:20:02 -0300 Subject: [PATCH 3/4] Removing a link to AWS doc from README --- README.markdown | 1 - 1 file changed, 1 deletion(-) diff --git a/README.markdown b/README.markdown index 0aefe11..85d1abb 100644 --- a/README.markdown +++ b/README.markdown @@ -80,7 +80,6 @@ try [dadbod-ui][]. [heroku.vim]: https://tpope.io/vim/heroku.git [rails.vim]: https://tpope.io/vim/rails.git [dadbod-ui]: https://github.com/kristijanhusak/vim-dadbod-ui -[Configuration and credential file settings]: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html ## Installation From 5067b0a62b332a6bb4e85bed2b722c398a515893 Mon Sep 17 00:00:00 2001 From: Samuel Abreu Date: Sat, 25 May 2024 16:49:44 -0300 Subject: [PATCH 4/4] Use sh -c to works properly with quotes --- autoload/db/adapter/dynamodb.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/db/adapter/dynamodb.vim b/autoload/db/adapter/dynamodb.vim index b42bebe..f5fb9f6 100644 --- a/autoload/db/adapter/dynamodb.vim +++ b/autoload/db/adapter/dynamodb.vim @@ -26,7 +26,7 @@ endfunction function! db#adapter#dynamodb#input(url, in) abort if filereadable(a:in) let lines = readfile(a:in) - return s:command(a:url, 'json') + split(lines[0]) + return ['sh', '-c'] + [join(s:command(a:url, 'json') + split(lines[0]))] endif return ['echo', 'no', 'command'] endfunction