{"id":13479776,"url":"https://github.com/kristijanhusak/vim-dadbod-ui","last_synced_at":"2025-05-14T09:08:15.240Z","repository":{"id":41422107,"uuid":"248737013","full_name":"kristijanhusak/vim-dadbod-ui","owner":"kristijanhusak","description":"Simple UI for https://github.com/tpope/vim-dadbod","archived":false,"fork":false,"pushed_at":"2025-03-26T18:04:35.000Z","size":416,"stargazers_count":1680,"open_issues_count":80,"forks_count":103,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-05T10:01:39.887Z","etag":null,"topics":["database","neovim","neovim-plugin","vim","vim-plugins","viml"],"latest_commit_sha":null,"homepage":"","language":"Vim Script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kristijanhusak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-20T11:17:28.000Z","updated_at":"2025-04-04T18:47:56.000Z","dependencies_parsed_at":"2024-01-16T06:28:06.821Z","dependency_job_id":"7e7ece26-fc5b-4e0f-9c9e-132c9924cede","html_url":"https://github.com/kristijanhusak/vim-dadbod-ui","commit_stats":{"total_commits":326,"total_committers":43,"mean_commits":"7.5813953488372094","dds":"0.34662576687116564","last_synced_commit":"0fec59e3e1e619e302198cd491b7d27f8d398b7c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristijanhusak%2Fvim-dadbod-ui","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristijanhusak%2Fvim-dadbod-ui/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristijanhusak%2Fvim-dadbod-ui/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristijanhusak%2Fvim-dadbod-ui/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kristijanhusak","download_url":"https://codeload.github.com/kristijanhusak/vim-dadbod-ui/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248567622,"owners_count":21125867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","neovim","neovim-plugin","vim","vim-plugins","viml"],"created_at":"2024-07-31T16:02:22.812Z","updated_at":"2025-04-12T12:37:11.730Z","avatar_url":"https://github.com/kristijanhusak.png","language":"Vim Script","funding_links":[],"categories":["Vim Script"],"sub_categories":[],"readme":"# vim-dadbod-ui\n\nSimple UI for [vim-dadbod](https://github.com/tpope/vim-dadbod).\nIt allows simple navigation through databases and allows saving queries for later use.\n\n![screenshot](https://i.imgur.com/fhGqC9U.png)\n\n\nWith nerd fonts:\n![with-nerd-fonts](https://i.imgur.com/aXI5BTG.png)\n\n\nVideo presentation by TJ:\n\n[![Video presentation by TJ](https://i.ytimg.com/vi/ALGBuFLzDSA/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==\u0026rs=AOn4CLDmOFtUnDmQx5U_PKBqV819YujOBw)](https://www.youtube.com/watch?v=ALGBuFLzDSA)\n\nTested on Linux, Mac and Windows, Vim 8.1+ and Neovim.\n\nFeatures:\n* Navigate through multiple databases and it's tables and schemas\n* Several ways to define your connections\n* Save queries on single location for later use\n* Define custom table helpers\n* Bind parameters (see `:help vim-dadbod-ui-bind-parameters`)\n* Autocompletion with [vim-dadbod-completion](https://github.com/kristijanhusak/vim-dadbod-completion)\n* Jump to foreign keys from the dadbod output (see `:help \u003cPlug\u003e(DBUI_JumpToForeignKey)`)\n* Support for nerd fonts (see `:help g:db_ui_use_nerd_fonts`)\n* Async query execution\n\n## Installation\n\nConfiguration with [lazy.nvim](https://github.com/folke/lazy.nvim)\n```lua\nreturn {\n  'kristijanhusak/vim-dadbod-ui',\n  dependencies = {\n    { 'tpope/vim-dadbod', lazy = true },\n    { 'kristijanhusak/vim-dadbod-completion', ft = { 'sql', 'mysql', 'plsql' }, lazy = true }, -- Optional\n  },\n  cmd = {\n    'DBUI',\n    'DBUIToggle',\n    'DBUIAddConnection',\n    'DBUIFindBuffer',\n  },\n  init = function()\n    -- Your DBUI configuration\n    vim.g.db_ui_use_nerd_fonts = 1\n  end,\n}\n```\n\nOr [vim-plug](https://github.com/junegunn/vim-plug)\n```vim\nPlug 'tpope/vim-dadbod'\nPlug 'kristijanhusak/vim-dadbod-ui'\nPlug 'kristijanhusak/vim-dadbod-completion' \"Optional\n```\n\nAfter installation, run `:DBUI`, which should open up a drawer with all databases provided.\nWhen you finish writing your query, just write the file (`:w`) and it will automatically execute the query for that database.\n\n## Databases\nThere are 3 ways to provide database connections to UI:\n\n1. [Through environment variables](#through-environment-variables)\n2. [Via g:dbs global variable](#via-gdbs-global-variable)\n3. [Via :DBUIAddConnection command](#via-dbuiaddconnection-command)\n\n#### Through environment variables\nIf `$DBUI_URL` env variable exists, it will be added as a connection. Name for the connection will be parsed from the url.\nIf you want to use a custom name, pass `$DBUI_NAME` alongside the url.\nEnv variables that will be read can be customized like this:\n\n```vimL\nlet g:db_ui_env_variable_url = 'DATABASE_URL'\nlet g:db_ui_env_variable_name = 'DATABASE_NAME'\n```\n\nOptionally you can leverage [dotenv.vim](https://github.com/tpope/vim-dotenv)\nto specific any number of connections in an `.env` file by using a specific\nprefix (defaults to `DB_UI_`). The latter part of the env variable becomes the\nname of the connection (lowercased)\n\n```bash\n# .env\nDB_UI_DEV=...          # becomes the `dev` connection\nDB_UI_PRODUCTION=...   # becomes the `production` connection\n```\n\nThe prefix can be customized like this:\n\n```vimL\nlet g:db_ui_dotenv_variable_prefix = 'MYPREFIX_'\n```\n\n#### Via g:dbs global variable\nProvide list with all databases that you want to use through `g:dbs` variable as an array of objects or an object:\n\n```vimL\nfunction s:resolve_production_url()\n  let url = system('get-prod-url')\n  return url\nend\n\nlet g:dbs = {\n\\ 'dev': 'postgres://postgres:mypassword@localhost:5432/my-dev-db',\n\\ 'staging': 'postgres://postgres:mypassword@localhost:5432/my-staging-db',\n\\ 'wp': 'mysql://root@localhost/wp_awesome',\n\\ 'production': function('s:resolve_production_url')\n\\ }\n```\n\nOr if you want them to be sorted in the order you define them, this way is also available:\n\n```vimL\nfunction s:resolve_production_url()\n  let url = system('get-prod-url')\n  return url\nend\n\nlet g:dbs = [\n\\ { 'name': 'dev', 'url': 'postgres://postgres:mypassword@localhost:5432/my-dev-db' }\n\\ { 'name': 'staging', 'url': 'postgres://postgres:mypassword@localhost:5432/my-staging-db' },\n\\ { 'name': 'wp', 'url': 'mysql://root@localhost/wp_awesome' },\n\\ { 'name': 'production', 'url': function('s:resolve_production_url') },\n\\ ]\n```\n\nIn case you use Neovim, here's an example with Lua:\n\n```lua\nvim.g.dbs = {\n    { name = 'dev', url = 'postgres://postgres:mypassword@localhost:5432/my-dev-db' },\n    { name = 'staging', url = 'postgres://postgres:mypassword@localhost:5432/my-staging-db' },\n    { name = 'wp', url = 'mysql://root@localhost/wp_awesome' },\n    {\n      name = 'production',\n      url = function()\n        return vim.fn.system('get-prod-url')\n      end\n    },\n}\n```\n\n\nJust make sure to **NOT COMMIT** these. I suggest using project local vim config (`:help exrc`)\n\n#### Via :DBUIAddConnection command\n\nUsing `:DBUIAddConnection` command or pressing `A` in dbui drawer opens up a prompt to enter database url and name,\nthat will be saved in `g:db_ui_save_location` connections file. These connections are available from everywhere.\n\n#### Connection related notes\nIt is possible to have two connections with same name, but from different source.\nfor example, you can have `my-db` in env variable, in `g:dbs` and in saved connections.\nTo view from which source the database is, press `H` in drawer.\nIf there are duplicate connection names from same source, warning will be shown and first one added will be preserved.\n\n## Settings\n\nAn overview of all settings and their default values can be found at `:help vim-dadbod-ui`.\n\n### Table helpers\nTable helper is a predefined query that is available for each table in the list.\nCurrently, default helper that each scheme has for it's tables is `List`, which for most schemes defaults to `g:db_ui_default_query`.\nPostgres, Mysql and Sqlite has some additional helpers defined, like \"Indexes\", \"Foreign Keys\", \"Primary Keys\".\n\nPredefined query can inject current db name and table name via `{table}` and `{dbname}`.\n\nTo add your own for a specific scheme, provide it through .`g:db_ui_table_helpers`.\n\nFor example, to add a \"count rows\" helper for postgres, you would add this as a config:\n\n```vimL\nlet g:db_ui_table_helpers = {\n\\   'postgresql': {\n\\     'Count': 'select count(*) from \"{table}\"'\n\\   }\n\\ }\n```\n\nOr if you want to override any of the defaults, provide the same name as part of config:\n```vimL\nlet g:db_ui_table_helpers = {\n\\   'postgresql': {\n\\     'List': 'select * from \"{table}\" order by id asc'\n\\   }\n\\ }\n```\n\n### Auto execute query\nIf this is set to `1`, opening any of the table helpers will also automatically execute the query.\n\nDefault value is: `0`\n\nTo enable it, add this to vimrc:\n\n```vimL\nlet g:db_ui_auto_execute_table_helpers = 1\n```\n\n### Icons\nThese are the default icons used:\n\n```vimL\nlet g:db_ui_icons = {\n    \\ 'expanded': '▾',\n    \\ 'collapsed': '▸',\n    \\ 'saved_query': '*',\n    \\ 'new_query': '+',\n    \\ 'tables': '~',\n    \\ 'buffers': '»',\n    \\ 'connection_ok': '✓',\n    \\ 'connection_error': '✕',\n    \\ }\n```\n\nYou can override any of these:\n```vimL\nlet g:db_ui_icons = {\n    \\ 'expanded': '+',\n    \\ 'collapsed': '-',\n    \\ }\n```\n\n### Help text\nTo hide `Press ? for help` add this to vimrc:\n\n```\nlet g:db_ui_show_help = 0\n```\n\nPressing `?` will show/hide help no matter if this option is set or not.\n\n### Drawer width\n\nWhat should be the drawer width when opened. Default is `40`.\n\n```vimL\nlet g:db_ui_winwidth = 30\n```\n\n### Default query\n\n**DEPRECATED**: Use [Table helpers](#table-helpers) instead.\n\nWhen opening up a table, buffer will be prepopulated with some basic select, which defaults to:\n```sql\nselect * from table LIMIT 200;\n```\nTo change the default value, use `g:db_ui_default_query`, where `{table}` is placeholder for table name.\n\n```vimL\nlet g:db_ui_default_query = 'select * from \"{table}\" limit 10'\n```\n\n### Save location\nAll queries are by default written to tmp folder.\nThere's a mapping to save them permanently for later to the specific location.\n\nThat location is by default `~/.local/share/db_ui`. To change it, addd `g:db_ui_save_location` to your vimrc.\n```vimL\nlet g:db_ui_save_location = '~/Dropbox/db_ui_queries'\n```\n\n## Mappings\nThese are the default mappings for `dbui` drawer:\n\n* o / \\\u003cCR\u003e - Open/Toggle Drawer options (`\u003cPlug\u003e(DBUI_SelectLine)`)\n* S - Open in vertical split (`\u003cPlug\u003e(DBUI_SelectLineVsplit)`)\n* d - Delete buffer or saved sql (`\u003cPlug\u003e(DBUI_DeleteLine)`)\n* R - Redraw (`\u003cPlug\u003e(DBUI_Redraw)`)\n* A - Add connection (`\u003cPlug\u003e(DBUI_AddConnection)`)\n* H - Toggle database details (`\u003cPlug\u003e(DBUI_ToggleDetails)`)\n\nFor queries, filetype is automatically set to `sql`. Also, two mappings is added for the `sql` filetype:\n\n* \\\u003cLeader\u003eW - Permanently save query for later use (`\u003cPlug\u003e(DBUI_SaveQuery)`)\n* \\\u003cLeader\u003eE - Edit bind parameters (`\u003cPlug\u003e(DBUI_EditBindParameters)`)\n\nAny of these mappings can be overridden:\n```vimL\nautocmd FileType dbui nmap \u003cbuffer\u003e v \u003cPlug\u003e(DBUI_SelectLineVsplit)\n```\n\nIf you don't want mappings to be added, add this to vimrc:\n```vimL\nlet g:db_ui_disable_mappings = 1       \" Disable all mappings\nlet g:db_ui_disable_mappings_dbui = 1  \" Disable mappings in DBUI drawer\nlet g:db_ui_disable_mappings_dbout = 1 \" Disable mappings in DB output\nlet g:db_ui_disable_mappings_sql = 1   \" Disable mappings in SQL buffers\nlet g:db_ui_disable_mappings_javascript = 1   \" Disable mappings in Javascript buffers (for Mongodb)\n```\n\n## Toggle showing postgres views in the drawer\nIf you don't want to see any views in the drawer, add this to vimrc:\nThis option must be disabled (set to 0) for Redshift.\n\n```vimL\nlet g:db_ui_use_postgres_views = 0\n```\n\n## Disable builtin progress bar\nIf you want to utilize *DBExecutePre or *DBExecutePost to make your own progress bar\nor if you want to disable the progress entirely set to 1.\n\n```vimL\nlet g:db_ui_disable_progress_bar = 1\n```\n\n## TODO\n\n* [ ] Test with more db types\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristijanhusak%2Fvim-dadbod-ui","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkristijanhusak%2Fvim-dadbod-ui","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristijanhusak%2Fvim-dadbod-ui/lists"}