My Latest Projects - ZenLibrary and Graffle2SQL

| | Comments (16)
You have 323 books from 363 authors and 67 publishers, 274 CDs from 120 artists, 44 DVDs from 40 directors, 2 games on 2 platforms, filed in 26 categories and located in 6 locations.

that is the front page of my latest webapp. A learning project to learn Ruby On Rails, a very nice web app framework that combines MVC, dynamic coding, and ruby rather well.

milestone 1) book title and author - 10 minutes

milestone 2) separate author and book tables - 20 minutes

milestone 3) real data from my website + location and category tables - 30 minutes

one hour and I had a rather well functioning library app w/ all my books in it. Really.

several milestones later and I have a VERY well functioning library app, fully normalized using utilities I added to help me with that (FINALLY! LoC can bite my ass!), supporting books, music, video and games with all my data in it.

It even looks pretty (not that grayson thinks so...bastard):

library screenshot

Anyone who's coded with me knows that while I try to make my code pretty, I don't do interfaces. But... rails made it so easy to do everything else that I actually bothered to make it pretty.

To top it off, I started a side project. Using the latest (internal) version of omnigraffle and an applescript I wrote, I now have automatic SQL generation. No more SQL for me!

Check out the schema:

library schema

This was made with OmniGraffle (very very easily I might add, using OG4, which is not publicly available yet) and then automatically converted into an SQL schema via applescript.

Just to drive it home... I did this in 845 lines of ruby. (I think that number is model/controller only, not view):

+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers          |   665 |   558 |      14 |      92 |   6 |     4 |
| Helpers              |   212 |   189 |       0 |       8 |   0 |    21 |
| Models               |   113 |    98 |      13 |      11 |   0 |     6 |
|   Units              |   120 |    84 |      12 |      12 |   1 |     5 |
|   Functionals        |   867 |   670 |      26 |     123 |   4 |     3 |
+----------------------+-------+-------+---------+---------+-----+-------+
| Total                |  1977 |  1599 |      65 |     246 |   3 |     4 |
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: 845     Test LOC: 754     Code to Test Ratio: 1.1:1

16 Comments

Can I suggest you reconsider your data model? There's a Drupal based project called LibDB that has a much richer� and more general� data model that you ought to be able to borrow or adapt. All your tables and fields are horribly concrete, which means the app will only ever adequately handle those specific objects you've defined upfront.

I'm a scholar, so interested in richer metadata. I'm also co-project lead for the OpenOffice bibliiographic project, and so am trying to promote a few related standards to get better interoperability.

You could argue it's not your thing, but I urge you to look at LibDB and see if you can't consider broadening what you're doing. See these postings of mine, and contact me if you have any questions: http://netapps.muohio.edu/blogs/darcusb/darcusb/index.php?s=libdb&submit=Search

Also, here's an interesting new BibTeX-based project: http://www.technotecture.com/software/SimplyBibTeX/. It's interesting from a GUI perspective (clever use of Javascript) and because it syndicates via RSS and Atom. I despise BibTeX though.

Anyway you can share that Ruby code for generating the PostgreSQL code from OmniGraffle?

Please!!!!

Hmm... DeZign for Databases will do the same thing, and also generate the SQL scripts. Oh, and if you want to convert your ERD from MySQL to DB2, well, it'll do that, too.

Only pimping it because I'm a satisfied user.

www.datanamic.com

...but it could be only Windows-based right now.

Unlike OmniGraffle, Visio, etc., DeZign isn't a general diagramming tool. It just does database ERDs, and does them pretty good.

"Anyway you can share that Ruby code for generating the PostgreSQL code from OmniGraffle?"

Actually, he said it was an AppleScript. Er, can you share that one then please? That sounds totally useful.

[I can, but I'm waiting for OG4 for usability reasons --zen]

I have a few questions about the SQL schema generation. I use OmniGraffle 3 (not professional) for creating ERDs but its a little rough. I have yet to sit down to figure out how to make a shape like the one in your diagram (a box with rows, each line a new row). I try but after a half hour of frustration I just do it by hand to "make it look good". It seems like your are implying that OG4 will have better tools for ERD creation. Also, I do a lot of work with Applescript so I would be very interested to see how you do your magic. Are you using features only availble in OG4 to implement your script? If not I would like to see the code just to attempt to "port" it for use with OG3.

Anyway, what a cool idea!

Tom,

Yes, I'm using features in OG4 that make life a lot easier for ERD (or UML, or pretty much anything else that has structure). But, I did convert my system to work w/ OG3. The main thing you need to do is make good use of stencils! Set up your shapes and magnets, maybe even cheat and make 1 by 2-10+ grouped shapes. Then heavily use tab to switch between objects when adding the text. Using the mouse just gets painful after a while.

I'm not too far from releasing my scripts and stencils...

Just consider this another plea for "Please release!" :)

Is it just me, or is the currently version of OmniGraffle actually completely useless for creating ERDs?

I've used a number of tools over the past 15 years to draw ERDs, ranging from high-end case tools to Visio and Kivio all the way down to Windows Paintbrush, and OmniGraffle seems to be about one step above paintbrush. Sure, it has some shapes and line formats, but where is the entity editor? Am I supposed to "draw" the table columns into the little box? It doesn't understand primary and foreign keys?

So far, I'm pretty glad I haven't paid any money for OmniGraffle. If paying money gets you a user's manual, that might be worthwhile, if the product actually has these features and isn't just a very pretty box-drawing program, but I'm not willing to risk seventy bucks just to find out.

Wes,

It must be you. Since writing a small applescript and creating a basic stencil, I haven't written a line of SQL since, and I love it.

While OG3 doesn't do as much to help you as OG4 will do, the ability to have groups of shapes each w/ their own magnets (and further, make a stencil of these at varying sizes) is very very efficient for creating ERDs (and UML, and flowcharts and ...).

As far as it not understanding primary and foreign keys... wtf? Where on the box (or website, or online help) does it say that it is anything more than a basic diagramming tool (at $70/$120 no less)? That is like complaining that Word's drawing tools don't have all the tools that photoshop has. It just isn't meant to. It is a whopping 17 meg application (that includes help) and launches in 4 seconds on my box. Nice and lean, easy to use, clean graphics. Not bloatware.

I haven't used Kivio (and I don't have high hopes for it either) but Visio is an overpriced ($200/$500) headache at best. It creates utterly crappy graphics and is hard to use. Basically, it does too much and does it poorly.

Let me recommend a few things for you:

  • Create a stencil or two - this will help a lot.
  • Use magnets, they rule.
  • Get a free trial license for pro and check out the mouseless editing features.
  • While you are at it, check out the visio xml import/export.
  • Quit your bitching! You got the tool for free! What (useful) tools do you get for free from M$?

I wasn't looking to "get it for free," I was looking for a useful tool for drawing ERDs. Try it yourself: google for "erd mac os x" and see that most of the hits mention OmniGraffle. Sure, you can draw an ERD with OmniGraffle, just like you can draw an ERD with a crayon, but it's really just down to drawing boxes and arrows.

I have Visio provided to me at work; I was looking for something better. All the usual complaints about Visio hold true here, the graphics are butt-ugly and the user interface is awful, etc., not to mention Winders crashing, locking up, or otherwise infuriating me several times a day.

The only thing I'm bitching about vis-a-vis OmniGraffle are all the (misguided? lying?) mentions that it provides ERD drawing capabilities. It doesn't. Don't say it does unless it really does. End of rant.

"Is it just me, or is the currently version of OmniGraffle actually completely useless for creating ERDs?"

No, it's not just you.

The only thing I've found that seems to handle it is DataArchitecht, but it's kind of kludgey feeling. I wish there was something like ERWin for OSX.

Claude,

As I said above, it MUST be you. You haven't given OG4 (or even 3) a fair shake... Again, using Graffle (a whopping $70 product), a small applescript, and a 1 object stencil I've done several rails apps and haven't written a single line of SQL in the last 8 months.

You wrote: "Again, using Graffle (a whopping $70 product), a small applescript, and a 1 object stencil I've done several rails apps and haven't written a single line of SQL in the last 8 months."

It would be terrific if you released these, so that the rest of us could see what it is you're excited about. I like OmniGraffle quite a bit (licensed 3.0 Pro user), but can't use it for ERDs, except to make pretty pictures. It would be nice to generate the SQL, too!

Getting ready to purchase OmniGraffle Pro -- would love to get a copy of the SQL generation script. Have you decided not to share it? It's been over a year, so I figure you may have decided not to release.

I too would love to get my grubby little hands on that AppleScript... are you willing to post it here? (Please!?)

Leave a comment