Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be explained in the help file, not the README.

Give a range to run part or all of the current buffer as a query.

:%DB mysql://root@localhost/bazquux
Expand Down Expand Up @@ -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

Expand Down
43 changes: 43 additions & 0 deletions autoload/db/adapter/dynamodb.vim
Original file line number Diff line number Diff line change
@@ -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