最近迷上了Vim 了,感觉它有无穷无尽的玩法。那么它可以用来简单的查oracle 数据库吗?因为有一些现场只有ssh远程,如果直接在命令行 sqlplus用来查,总感觉体验不是很好。如果可以使用vim插件来查数据库会不会体验好一些呢?
vim-dadbodDadbod是一个用于与数据库交互的Vim插件。 项目地址: https://github.com/tpope/vim-dadbod
vim-dadbod-ui基于 vim-dadbod有图形化界面,比较好上手。 安装 我使用的是:Vundle插件管理器
Plugin 'kristijanhusak/vim-packager'
Plugin 'tpope/vim-dadbod'
Plugin 'kristijanhusak/vim-dadbod-ui'
:PluginList
安装就搞定了。
数据源配置。 比如:
vim ~/.vim/vimrc
这里我以oracle为例。
let g:dbs = [
\ { 'name': 'centos', 'url': 'oracle://usr_sg:apexsoft@CentOS' },
\ { 'name': 'centos2', 'url': 'oracle:usr_sg/apexsoft@172.16.184.5:1521/orcl' }
\ ]
第一种是连接 tnsnames.ora 中配置的服务的形式。 第二种是直接连接的方式。 个人感觉第二种方式更简单直接一些。
查sql:DBUI
打开界面。 输入sql 在执行 :w后就会执行查询操作了。
vim的配置文件中加入以下内容,开启图标显示
let g:db_ui_use_nerd_fonts=1
显示效果确实要好一些了。
这下有图标了。
如果图标显示乱码,说明字体没有安装完成,可以参考《macOS中SpaceVim搭建java开发环境》 搜索 “字体乱码问题”
帮助*dadbod.txt*
Author: Tim Pope
Repo: https://github.com/tpope/vim-dadbod
License: Same terms as Vim itself (see |license|)
USAGE *dadbod* *:DB*
:DB [url] Start an interactive database console. Uses
dispatch.vim's |:Start| if available.
:DB [url] {cmd} Run {cmd} on the selected database and show the
results in a preview window.
:{range}DB [url] Run the lines referenced by {range} on the selected
database and show the results in a preview window.
:DB [url] < {file} Run the given {file} on the selected database and show
the results in a preview window.
:DB {var} = {url} Assign the canonicalization of {url} to a |g:|, |w:|,
|t:|, |b:|, or environment variable.
:DB [url] :{command} Run the Vim command {command} with the given URL set
as the default. This is mainly useful with
|g:dadbod_manage_dbext|.
In the preview window, you can press "R" to rerun, "r" to interactively rerun,
or "q" to close the window.
URLS *dadbod-urls*
URLs are adapter specific but generally take one of two formats:
>
adapter://[user[:password]@][host][:port]/[database]
adapter:[database]
A complete reference is below under |dadbod-adapters|, but a few examples should
mostly get the point across:
>
postgresql://postgres:secret@remote-host/test
mysql://root@localhost/test
sqlite:db.sqlite3
mongodb:///admin
redis:///
<
Additionally, one can give:
* A Vim variable (e.g., g:foo, w:bar, t:baz, b:quux) or environment variable
(e.g., $DATABASE_URL) containing a URL.
* File name of a supported database file (e.g. ~/db.sqlite3). Relative paths
must start with "./", and spaces must be %20 URL encoded (NOT backslash
escaped).
VARIABLES *dadbod-variables*
If a |w:|, |t:|, |b:|, |g:|, or $ENVIRONMENT variable is given as a URL, its
value will be used. Additionally, if no URL is given, the first of w:db,
t:db, b:db, $DATABASE_URL, and g:db will be used. Suggested uses:
* w:db is best set interactively.
* b:db is most useful when set from an |autocommand|.
* g:db and other globals can be set in your |vimrc| or other startup file.
* $DATABASE_URL and other environment variables are easy to set externally.
Set a variable with |:let|, or use |:DB| to normalize the URL first:
>
:DB w:db = adapter://...
<
ADAPTERS *dadbod-adapters*
*dadbod-dbext*
dbext ~
>
dbext:type=[:=][...]
dbext:profile=[...]
<
For supported adapters, dbext modelines and profiles can be used directly.
*dadbod-impala*
Impala ~
>
impala://[[:]]/[]
<
*dadbod-jq*
jq ~
>
jq:relative/path
jq:/absolute/path
jq:C:/windows/path
jq:///relative/or/absolute/path
<
An empty path runs jq without input, see --null-input parameter.
*dadbod-mongodb*
MongoDB ~
>
mongodb://[[:]@][[:]]/[][?ssl=true]
mongodb:[]
<
*dadbod-mysql*
MySQL ~
>
mysql://[[:]@][[:]]/[database]
mysql://[[:]@][]/[]
mysql:///[]?login-path=
mysql:[]
<
*dadbod-oracle*
Oracle ~
>
oracle://[[:]@][][:]/[]
oracle:/@[//][:]/
<
*dadbod-osquery*
osquery ~
>
osquery:relative/path
osquery:/absolute/path
osquery:C:/windows/path
osquery:///relative/or/absolute/path
<
An empty path portion uses an in-memory database, which is how osquery is
typically invoked.
*dadbod-postgresql*
PostgreSQL ~
>
postgresql://[[:]@][[:]]/[]
postgresql://[[:]@][]/[]
postgresql:[]
<
For interop, postgres:// URLs are also accepted.
*dadbod-presto*
Presto ~
>
presto://[[:]]/[[/]]
<
*dadbod-redis*
Redis ~
>
redis://[[unused[:]@]]/[]
redis:[]
<
Redis doesn't have a username, so use a dummy one in the URL if a password is
required.
*dadbod-sqlserver*
SQL Server ~
>
sqlserver://[[:]@][][:]/[]
sqlserver://[[:]][;user=][;...]
sqlite:relative/path
sqlite:/absolute/path
sqlite:C:/windows/path
sqlite:///relative/or/absolute/path
let g:dadbod_manage_dbext = 1
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?