kristijanhusak / vim-dadbod-completion

Database autocompletion powered by https://github.com/tpope/vim-dadbod

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Caching Behavior Preventing Completion of New Tables

alreadytold opened this issue · comments

There seems to be an issue with the way that plugin refreshes database tables and columns information.

I was only able to give a cursory look at what is happening here, but it seems that the cache is not being updated after the plugin loads, and I have no idea how to reload the plugin.

For example, if I open a new buffer with filetype=sql, completion works with all of the existing tables and columns.

However, if I now create a new table, :enew with filetype=sql appears to reconnect to the database, but completion doesn't consider the new table at all.

These lines of code seems to be preventing the plugin from reloading the tables and columns into the cache:

function! s:save_to_cache(bufnr, db, table, dbui) abort
...
  if has_key(s:cache, a:db)
    return
  endif
...
endfunction

If I use :DBUI, refreshing and creating a new query works to include the newly created table for completion, but doesn't seem to be aware of its columns, because they do not appear when I try to complete them.

Is there something that I am missing here?

Since there is no easy way to update the cache, I introduced a command to clear it.
Just run :DBCompletionClearCache and it will clear all the cache, and if you are in the SQL buffer it will automatically cache new data. Hope this helps.

Thanks