General infrastructure/design question - long

Bill Witherspoon billw at witherspoon-design.com
Mon Nov 19 14:57:02 EST 2001


(First - this is a great list, I learn alot everyday just reading the posts. You should all be congratulated for this!)
(Second - I'm not a professional so this question may seem, well, a bit off...)

I'm writing an app for small businesses which have to 'track' clients and schedule visits, (dentist, barber,etc.) I'm using mySQL right now but hope to keep my programming abstract enough to use Postgres, or another db.

I've written a wrapper over the MySQLdb module (thanks Andy) which allows me to open a database, and execute queries in a very simple fashion. Another module has all of the classes which I want to load with data (like client info).  I can load a 'client' object with info from the database with a line like: client1 = appclasses.Client(queryresults[0]), where queryresults was a SQL query on the db.

This loads the data into the appropriate object 'properties' using the client class's __init__ method.

whew... almost there

Is there a better way to do this? 

My fear is that everytime I change the db schema, I have to run around and update all of the classes to insure that the data maps correctly. Is there any way to easily have a class that 'knows' how to create its own __init__ so that the db fields always become appropriate properties?

ie. (passing the db schema, and values for a particular client)

class Client:
	def __init__(self, attributevalues, schema):
		Loop through schema list and create properties

so that I end up with:

	client1.Name = 'Bill'
	client1.Address = yadayada...

and if I add a field to the db (like phnumber), the next time I instantiate a client object it will have a phnumber property.
(Without changing the __init__ code).

Is this ridiculous? I assume everyone faces this problem so I'm hoping someone can give me a little guidence.

TIA,
Bill.




More information about the Python-list mailing list