Ⅰ. 插件描述
database interface for vimⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'kamichidu/vim-vdbc'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'kamichidu/vim-vdbc'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'kamichidu/vim-vdbc'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/kamichidu/vim-vdbc
Ⅳ. 文档说明
vim-vdbc 
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)
Installation
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', \ }, \}
How to Use
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
endtrySee :help vdbc-contents for more details.
Dependencies
| 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 |