Skip to content

Commit

Permalink
Add Snowflake support (#174)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Pope <code@tpope.net>
  • Loading branch information
ctdunc and tpope authored Oct 18, 2024
1 parent b74e49c commit fe5a55e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ take on [dbext.vim][], improving on it on the following ways:
- PostgreSQL
- Presto
- Redis
- Snowflake
- SQL Server
- SQLite
- Your own easily implemented adapter
Expand Down
31 changes: 31 additions & 0 deletions autoload/db/adapter/snowflake.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function! db#adapter#snowflake#interactive(url) abort
let url = db#url#parse(a:url)
let cmd = (has_key(url, 'password') ? ['env', 'SNOWSQL_PWD=' . url.password] : []) +
\ ["snowsql"] +
\ db#url#as_argv(a:url, '-a ', '', '', '-u ', '','-d ')
for [k, v] in items(url.params)
call add(cmd, '--' . k . '=' . v)
endfor
return cmd
endfunction

function! db#adapter#snowflake#filter(url) abort
return db#adapter#snowflake#interactive(a:url) +
\ ['-o', 'friendly=false', '-o', 'timing=false']
endfunction

function! db#adapter#snowflake#input(url, in) abort
return db#adapter#snowflake#filter(a:url) + ['-f', a:in]
endfunction

function! db#adapter#snowflake#complete_opaque(url) abort
return db#adapter#snowflake#complete_database(url)
endfunction

function! db#adapter#snowflake#complete_database(url) abort
let pre = matchstr(a:url, '[^:]\+://.\{-\}/')
let cmd = db#adapter#snowflake#filter(pre) +
\ ['-o', 'header=false', '-o', 'output_format=tsv'] +
\ ['-q', 'show terse databases']
return map(db#systemlist(cmd), { _, v -> split(v, "\t")[1] })
endfunction
8 changes: 8 additions & 0 deletions doc/dadbod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ Redis ~
Redis doesn't have a username, so use a dummy one in the URL if a password is
required.

*dadbod-snowflake*
Snowflake ~
>
snowflake://[<user>[:<password>]@[<accountname>]]/[<database>]
<
Query parameters can be used to set additional command line options (e.g.,
`?warehouse=foo`).

*dadbod-sqlserver*
SQL Server ~
>
Expand Down

0 comments on commit fe5a55e

Please sign in to comment.