-
Notifications
You must be signed in to change notification settings - Fork 11
Database Explorer
Every decent Oracle IDE has a database explorer which may be used to navigate through the database objects in an hierarchical way. Vorax provides such a feature as well.
The following key mappings are relevant in the context of the database explorer:
-
<Leader>ve
- Toggle the explorer window.ve
stands for "Vorax Explorer". -
m
- Invokes the contextual menu for an explorer node. -
o
orENTER
- Edit the object definition or expand/collapse a category -
R
- Refresh the database explorer. -
<Leader>d
- describe the selected database object -
<Leader>D
- verbose describe the selected table
The database explorer may be configured using the following global variables:
-
g:vorax_dbexplorer_force_edit
: whenever or not to get the object definition directly from the database or, if a local file matching the object name exists, to open that file instead (default value). Please seeVORAXEdit
vs.VORAXEdit!
. -
g:vorax_dbexplorer_exclude
: a Vim style regular expression which may be used to filter the categories some might not be interested in. -
g:vorax_db_explorer_side
: where to layout the database explorer window:left
orright
. By default it'sleft
. -
g:vorax_db_explorer_size
: the size of the explorer window. The default value is30
.
The contextual menu of the database explorer can be extended using custom plugins. In fact, every option you see in the menu is provided by a plugin. Of course, you're free to write your own super-mega-cool plugins.
A plugin is just a vim script which must reside in vorax/plugin/explorer
folder. It has a very simple interface:
let s:plugin = {
\ 'text': 'my test plugin',
\ 'shortcut' : 't'}
function! s:plugin.Callback(descriptor)
" do stuff here
endfunction
function! s:plugin.IsEnabled(descriptor)
" decide if the plugin should be activated for the current item
endfunction
call vorax#explorer#RegisterPluginItem(s:plugin)
Let's have a look at the code above. In text
we put the label we want to appear in the contextual menu. The shortcut
is, obvious, the shortcut which may be used to invoke the menu item implemented by the plugin.
There are two functions: Callback
and IsEnabled
. Both are invoked with a handler, describing the selected node from the explorer tree. We'll come back to this descriptor shortly. The IsEnabled
function is where you decide if your plugin is valid for the selected node. For example, a plugin for collecting table statistics wouldn't make sense for a package. The Callback
function is where you put your plugin logic. It is the code which is run when the user invokes the menu item provided by your plugin.
The descriptor
argument is a hash which describes the selected node from the database explorer. It has the following keys:
-
object
: is the object name, as it is shown in the explorer. If the current item is not a database object, the value of this key is ''. -
owner
: is the owner of the object. It's empty if the selected item is not a database object. -
category
: the category to which the node belongs to. Could be: "Tables", "Packages" etc. -
dbtype
: is the Oracle type of the selected node -
status
: the status of the object:VALID
orINVALID
The above information should be enough to determine the context in which your plugins operates.
The final step is to register the plugin using the RegisterPluginItem
function.
You may have a look into your vorax/plugin/explorer
folder to see other examples of already implemented plugins. Please note that every plugin script file starts with a number. This is a convenient way of ordering the menu items when the contextual menu is displayed.