The generic database interface for vim.
This plug-in intended to give some generic API to vim plug-in developers, and high-speed database accessing (via vim's libcall feature).
Implemented features:
- transaction support
- prepared statement support
- introspection support (depends on a driver)
You can choose a driver you want to use it. Available drivers are:
- pg
- pg_libpq
- sqlite3
- sqlite3_libsqlite3
After choosing your favourite driver, you can write following settings to $MYVIMRC
.
NOTE: You have to install some dependencies.
-
pg
NeoBundle 'kamichidu/vim-vdbc', { \ 'depends': ['Shougo/vimproc.vim'], \ 'external_commands': 'psql', \}
-
pg_libpq
NeoBundle 'kamichidu/vim-vdbc', { \ 'build': { \ 'unix': 'make -f Makefile pg_libpq', \ 'windows': 'make -f Makefile.win64 pg_libpq', \ }, \}
-
sqlite3
NeoBundle 'kamichidu/vim-vdbc', { \ 'depends': ['Shougo/vimproc.vim'], \ 'external_commands': 'sqlite3', \}
-
sqlite3_libsqlite3
On this driver, we bundled sqlite3 sources and dynamic library for windows 64-bit. If you use windows 64-bit, you can use sqlite3_libsqlite3 driver without compiling it.
NeoBundle 'kamichidu/vim-vdbc', { \ 'build': { \ 'unix': 'make -f Makefile sqlite3_libsqlite3', \ }, \}
Basic usage is below:
" driver is one of {'pg', 'pg_libpq', 'sqlite3', 'sqlite3_libsqlite3'}
try
let conn= vdbc#connect_by_dsn('vdbc:sqlite3*:dbname=:memory:')
call conn.execute('create table a_table (column1 integer, column2 varchar)')
" => [[1, 'hoge'], [2, 'fuga'], ...]
echo conn.select_as_list('select * from a_table where column2 = ?', ['param'])
" => [{'column1': 1, 'column2': 'hoge'}, {'column1': 2, 'column2': 'fuga'}, ...]
echo conn.select_as_dict('select * from a_table where column2 = ?', ['param'])
finally
if exists('conn')
call conn.disconnect()
endif
endtry
See :help vdbc-contents
for more details.
Driver | OS | Dependency | make command example |
---|---|---|---|
pg | Ubuntu 14.x | postgresql-client-9.3 | - |
| Arch Linux | postgresql-libs | -
pg_libpq | Ubuntu 14.x | libpq5 | make INCDIR="-I/usr/include/postgresql/" pg_libpq | | libpq-dev | | Arch Linux | postgresql-libs | make pg_libpq sqlite3 | Ubuntu 14.x | sqlite3 | - | Arch Linux | sqlite | - sqlite3_libsqlite3 | - | - | make sqlite3_libsqlite3