Vim用来当SQL Server Client?

19 篇文章 1 订阅

最近迷上了Vim 了,感觉它有无穷无尽的玩法。那么它可以用来简单的查oracle 数据库吗?因为有一些现场只有ssh远程,如果直接在命令行 sqlplus用来查,总感觉体验不是很好。如果可以使用vim插件来查数据库会不会体验好一些呢?

vim-dadbod

Dadbod是一个用于与数据库交互的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后就会执行查询操作了。
在这里插入图片描述

使用 nerd fonts图标

vim的配置文件中加入以下内容,开启图标显示

let g:db_ui_use_nerd_fonts=1

显示效果确实要好一些了。
在这里插入图片描述

这下有图标了。

如果图标显示乱码,说明字体没有安装完成,可以参考《macOS中SpaceVim搭建java开发环境》
搜索 “字体乱码问题”

帮助

*dadbod.txt*

Author:  Tim Pope <http://tpo.pe/>
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=<type>[:<attr>=<value>][...]
    dbext:profile=<profile>[...]
<
For supported adapters, dbext modelines and profiles can be used directly.

                                                *dadbod-impala*
Impala ~
>
    impala://[<host>[:<port>]]/[<database>]
<
                                                *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://[<user>[:<password>]@][<host>[:<port>]]/[<database>][?ssl=true]
    mongodb:[<database>]
<
                                                *dadbod-mysql*
MySQL ~
>
    mysql://[<user>[:<password>]@][<host>[:<port>]]/[database]
    mysql://[<user>[:<password>]@][<%2Fsocket%2Fpath>]/[<database>]
    mysql:///[<database>]?login-path=<login-path>
    mysql:[<database>]
<
                                                *dadbod-oracle*
Oracle ~
>
    oracle://[<user>[:<password>]@][<host>][:<port>]/[<database>]
    oracle:<user>/<password>@[//]<host>[:<port>]/<database>
<
                                                *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://[<user>[:<password>]@][<host>[:<port>]]/[<database>]
    postgresql://[<user>[:<password>]@][<%2Fsocket%2Fpath>]/[<database>]
    postgresql:[<database>]
<
For interop, postgres:// URLs are also accepted.

                                                *dadbod-presto*
Presto ~
>
    presto://[<host>[:<port>]]/[<catalog>[/<schema>]]
<
                                                *dadbod-redis*
Redis ~
>
    redis://[[unused[:<password>]@]<host>]/[<database-number>]
    redis:[<database-number>]
<
Redis doesn't have a username, so use a dummy one in the URL if a password is
required.

                                                *dadbod-sqlserver*
SQL Server ~
>
    sqlserver://[<user>[:<password>]@][<host>][:<port>]/[<database>]
    sqlserver://[<host>[:<port>]][;user=<user>][;...]
<
If the user and password are omitted, a trusted connection is used.

                                                *dadbod-sqlite*
SQLite ~
>
    sqlite:relative/path
    sqlite:/absolute/path
    sqlite:C:/windows/path
    sqlite:///relative/or/absolute/path
<
In the wild, uses of sqlite:///path vary on whether the path is relative or
absolute, so both are checked.  The preferred form is sqlite:path, which
avoids this ambiguity.

An empty path portion uses an in-memory database, which is occasionally useful
for an interactive invocation.

DBEXT MANAGEMENT                                *g:dadbod_manage_dbext*

If you like Dadbod's configuration but need some of dbext's functionality, set
the following variable to enable an experimental mode where dbext's
configuration always mirrors Dadbod's default.
>
  let g:dadbod_manage_dbext = 1
<
 vim:tw=78:et:ft=help:norl:

总结

使用以后,感觉跟使用sqlplus差不了多少,只是体验略好一些,比起PL\SQL之类的工具还是差太远了。用于临时查询维护数据库还是不错的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值