views:

50

answers:

2

Given a [mysql] database with a given schema, is it possible to generate an ORM interface for it? doesn't matter if its php, python or perl.

in other words, I have a database and I have to ask it a few questions. while I could just craft a bunch of SQL queries (okay, several dozen), this is way more interesting to think about.

is this a valid question, even? I have no design background with ORMs, but I've used a few (django's, symfony's, etc).

A: 

I'm not sure exactly what you're asking, but I suspect the answer is "sure, you can point an ORM tool at an existing database and get back some classes that are somewhat useful"

Doctrine comes to mind as a PHP ORM tool that can (sort of) do this. If your schema has reasonable names for things, it will do it's best to discover relationships for you, etc.

Not sure that it's actually worth the effort, but if you're curious, why not give it a spin?

timdev
+3  A: 

Django's ORM will do this for you (or at least it will get the process started for you).

Just set up a django app as you normally would (including DB connection settings), then do this:

$ python manage.py inspectdb > models.py

I did this once to help me make sense of a legacy (php) website database that I was tasked with maintaining. It was a little work, but ultimately I was able to use the django admin site to manage it (the project was shelved, but that's another story).

See: http://docs.djangoproject.com/en/dev/howto/legacy-databases/

Seth
that's super cool. I'll have to check this out.
Oren Mazor