Before leaving on a recent business trip to Italy I begun working on a TextMate bundle for DB2. Here I’ll introduce it in the hope that it will interest some TextMate and DB2 users.
There are two simple prerequisites for using this bundle: 1) Install DB2 as a regular user (not root); 2) Source the db2profile by, for example, adding
. ~/sqllib/db2profile to your shell profile (e.g., in
~/.profile). Both of these will ensure that your user is able to issue DB2 commands.
To install the bundle, you can run the following (assuming you have git installed):
sudo mkdir -p /Library/Application<span class="se">\ </span>Support/TextMate/Bundles
<span class="nb">cd</span> /Library/Application<span class="se">\ </span>Support/TextMate/Bundles
git clone git://github.com/acangiano/db2-textmate-bundle.git <span class="s2">"DB2.tmbundle"</span>
Alternatively, you can download this file, unzip it and then double click on the DB2.tmbundle that was extracted. Of course, the previous method has the advantage of being able to easily update the bundle through
If TextMate is running while you executed the previous step, you may want to also execute the following line:
osascript -e <span class="s1">'tell app "TextMate" to reload bundles'</span>
This is equivalent to selecting Bundles ? Bundle Editor ? Reload Bundles from within TextMate.
Using the bundle
If you followed the instructions above, at this point you should see a DB2 menu under Bundles:
TextMate is a text editor, and as such it expects you to have an open document, in order to execute commands from this bundle. The good news is that an empty, untitled, open by default window will suffice.
As you can see from the image above, you can start the DB2 server, stop it, run an arbitrary query or DB2 command and open up the Information Center for DB2 9.5 in your browser. Below the separating line there are also two submenus, Database and Tables.
Let’s consider Database first:
Within the Database menu we can connect to a database (this step is required before being able to query a database), disconnect, create a database, drop it, and create the SAMPLE database that ships with DB2 so you can get some practice.
Likewise, while it’s at a very early stage of development, we have the Tables submenu:
So far we can list the tables within the database we are currently connected to, and drop an existing table.
You can use the Shift-Command-D combination to bring up a convenient contextual menu of the most common tasks, while you are within a document (unless you are editing an HTML file, in which case that combination brings up Safari):
The result of each command executed is flashed to the user in the form of an informative tooltip:
The aim of this bundle is to provide a more convenient way to work with DB2 without having to switch between your coding editor and the command line. It’s admittedly just a “seed”, a very early effort, but I sincerely hope that even at this stage it can be useful to some people. Being an open source project that’s released under the MIT license, you are free to contribute to it and more than welcome to fork it on Github as well.
Get more stuff like this
Subscribe to my mailing list to receive similar updates about programming.
Thank you for subscribing. Please check your email to confirm your subscription.
Something went wrong.