- Notifications
You must be signed in to change notification settings - Fork113
Simple UI forhttps://github.com/tpope/vim-dadbod
License
kristijanhusak/vim-dadbod-ui
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Simple UI forvim-dadbod.It allows simple navigation through databases and allows saving queries for later use.
Video presentation by TJ:
Tested on Linux, Mac and Windows, Vim 8.1+ and Neovim.
Features:
- Navigate through multiple databases and it's tables and schemas
- Several ways to define your connections
- Save queries on single location for later use
- Define custom table helpers
- Bind parameters (see
:help vim-dadbod-ui-bind-parameters) - Autocompletion withvim-dadbod-completion
- Jump to foreign keys from the dadbod output (see
:help <Plug>(DBUI_JumpToForeignKey)) - Support for nerd fonts (see
:help g:db_ui_use_nerd_fonts) - Async query execution
Configuration withlazy.nvim
return {'kristijanhusak/vim-dadbod-ui',dependencies= { {'tpope/vim-dadbod',lazy=true }, {'kristijanhusak/vim-dadbod-completion',ft= {'sql','mysql','plsql'},lazy=true },-- Optional },cmd= {'DBUI','DBUIToggle','DBUIAddConnection','DBUIFindBuffer', },init=function()-- Your DBUI configurationvim.g.db_ui_use_nerd_fonts=1end,}
Orvim-plug
Plug'tpope/vim-dadbod'Plug'kristijanhusak/vim-dadbod-ui'Plug'kristijanhusak/vim-dadbod-completion'"Optional
After installation, run:DBUI, which should open up a drawer with all databases provided.When you finish writing your query, just write the file (:w) and it will automatically execute the query for that database.
There are 3 ways to provide database connections to UI:
If$DBUI_URL env variable exists, it will be added as a connection. Name for the connection will be parsed from the url.If you want to use a custom name, pass$DBUI_NAME alongside the url.Env variables that will be read can be customized like this:
letg:db_ui_env_variable_url='DATABASE_URL'letg:db_ui_env_variable_name='DATABASE_NAME'
Optionally you can leveragedotenv.vimto specify any number of connections in an.env file by using a specificprefix (defaults toDB_UI_). The latter part of the env variable becomes thename of the connection (lowercased)
# .envDB_UI_DEV=...# becomes the `dev` connectionDB_UI_PRODUCTION=...# becomes the `production` connection
The prefix can be customized like this:
letg:db_ui_dotenv_variable_prefix='MYPREFIX_'
Provide list with all databases that you want to use throughg:dbs variable as an array of objects or an object:
functions:resolve_production_url()let url=system('get-prod-url')return urlendletg:dbs= {\'dev':'postgres://postgres:mypassword@localhost:5432/my-dev-db',\'staging':'postgres://postgres:mypassword@localhost:5432/my-staging-db',\'wp':'mysql://root@localhost/wp_awesome',\'production':function('s:resolve_production_url')\}
Or if you want them to be sorted in the order you define them, this way is also available:
functions:resolve_production_url()let url=system('get-prod-url')return urlendletg:dbs= [\{'name':'dev','url':'postgres://postgres:mypassword@localhost:5432/my-dev-db' }\{'name':'staging','url':'postgres://postgres:mypassword@localhost:5432/my-staging-db' },\{'name':'wp','url':'mysql://root@localhost/wp_awesome' },\{'name':'production','url':function('s:resolve_production_url') },\]
In case you use Neovim, here's an example with Lua:
vim.g.dbs= { {name='dev',url='postgres://postgres:mypassword@localhost:5432/my-dev-db'}, {name='staging',url='postgres://postgres:mypassword@localhost:5432/my-staging-db'}, {name='wp',url='mysql://root@localhost/wp_awesome'}, {name='production',url=function()returnvim.fn.system('get-prod-url')end },}
Just make sure toNOT COMMIT these. I suggest using project local vim config (:help exrc)
Using:DBUIAddConnection command or pressingA in dbui drawer opens up a prompt to enter database url and name,that will be saved ing:db_ui_save_location connections file. These connections are available from everywhere.
It is possible to have two connections with same name, but from different source.for example, you can havemy-db in env variable, ing:dbs and in saved connections.To view from which source the database is, pressH in drawer.If there are duplicate connection names from same source, warning will be shown and first one added will be preserved.
An overview of all settings and their default values can be found at:help vim-dadbod-ui.
Table helper is a predefined query that is available for each table in the list.Currently, default helper that each scheme has for it's tables isList, which for most schemes defaults tog:db_ui_default_query.Postgres, Mysql and Sqlite has some additional helpers defined, like "Indexes", "Foreign Keys", "Primary Keys".
Predefined query can inject current db name and table name via{table} and{dbname}.
To add your own for a specific scheme, provide it through .g:db_ui_table_helpers.
For example, to add a "count rows" helper for postgres, you would add this as a config:
letg:db_ui_table_helpers= {\'postgresql': {\'Count':'select count(*) from "{table}"'\ }\}
Or if you want to override any of the defaults, provide the same name as part of config:
letg:db_ui_table_helpers= {\'postgresql': {\'List':'select * from "{table}" order by id asc'\ }\}
Overriding a helper with an empty string will remove it.
letg:db_ui_table_helpers= {\'postgresql': {\'List':''\ }\}
If this is set to1, opening any of the table helpers will also automatically execute the query.
Default value is:0
To enable it, add this to vimrc:
letg:db_ui_auto_execute_table_helpers=1
These are the default icons used:
letg:db_ui_icons= {\'expanded':'▾',\'collapsed':'▸',\'saved_query':'*',\'new_query':'+',\'tables':'~',\'buffers':'»',\'connection_ok':'✓',\'connection_error':'✕',\}
You can override any of these:
letg:db_ui_icons= {\'expanded':'+',\'collapsed':'-',\}
To hidePress ? for help add this to vimrc:
let g:db_ui_show_help = 0Pressing? will show/hide help no matter if this option is set or not.
What should be the drawer width when opened. Default is40.
letg:db_ui_winwidth=30
DEPRECATED: UseTable helpers instead.
When opening up a table, buffer will be prepopulated with some basic select, which defaults to:
select*from tableLIMIT200;
To change the default value, useg:db_ui_default_query, where{table} is placeholder for table name.
letg:db_ui_default_query='select * from "{table}" limit 10'
All queries are by default written to tmp folder.There's a mapping to save them permanently for later to the specific location.
That location is by default~/.local/share/db_ui. To change it, adddg:db_ui_save_location to your vimrc.
letg:db_ui_save_location='~/Dropbox/db_ui_queries'
These are the default mappings fordbui drawer:
- o / <CR> - Open/Toggle Drawer options (
<Plug>(DBUI_SelectLine)) - S - Open in vertical split (
<Plug>(DBUI_SelectLineVsplit)) - d - Delete buffer or saved sql (
<Plug>(DBUI_DeleteLine)) - R - Redraw (
<Plug>(DBUI_Redraw)) - A - Add connection (
<Plug>(DBUI_AddConnection)) - H - Toggle database details (
<Plug>(DBUI_ToggleDetails))
For queries, filetype is automatically set tosql. Also, two mappings is added for thesql filetype:
- <Leader>W - Permanently save query for later use (
<Plug>(DBUI_SaveQuery)) - <Leader>E - Edit bind parameters (
<Plug>(DBUI_EditBindParameters))
Any of these mappings can be overridden:
autocmdFileTypedbuinmap<buffer>v<Plug>(DBUI_SelectLineVsplit)
If you don't want mappings to be added, add this to vimrc:
letg:db_ui_disable_mappings=1" Disable all mappingsletg:db_ui_disable_mappings_dbui=1" Disable mappings in DBUI drawerletg:db_ui_disable_mappings_dbout=1" Disable mappings in DB outputletg:db_ui_disable_mappings_sql=1" Disable mappings in SQL buffersletg:db_ui_disable_mappings_javascript=1" Disable mappings in Javascript buffers (for Mongodb)
If you don't want to see any views in the drawer, add this to vimrc:This option must be disabled (set to 0) for Redshift.
letg:db_ui_use_postgres_views=0
If you want to utilize *DBExecutePre or *DBExecutePost to make your own progress baror if you want to disable the progress entirely set to 1.
letg:db_ui_disable_progress_bar=1
- Test with more db types
About
Simple UI forhttps://github.com/tpope/vim-dadbod
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.


