Databases, applescript and Omnigraffle

Last friday I spent an hour or 2 and wrote a simple applescript to visualize mysql databases in OmniGraffle. I find it easier to write SQL code when I look at the database structure in chart form.

When you run the script you get all the database tables, like so:

You then have to manually organize them and draw the lines between them. (The script adds line magnets that make this process fairly simple).

Here is an html listing of the script source code, and here is a compiled version of the script.

You will need to edit a couple lines in the beginning of the script in order to get it to work for you. You’ll also need the applescript xml tools, mysql installed on your mac, and of course, Omnigraffle.

What? you say. XML tools? Yes. If you look at the script you will see a clever little hack where I use the mysql command line tools to produce xml results from SQL queries. I get the SQL results back into applescript by parsing the XML data into arrays.

Search weblog content

Syndication RSS
RDF