Hello Django-Users,

The software development team at the Campbell-Lange Workshop (CLW) has
been using Django since 0.95. From the beginning we have been very
impressed with the URL dispatcher, form validation and templating
language. We have, however, found that the Django ORM occasionally
doesn't meet our requirements when writing complex web-services.

Having unsuccessfully scanned the Django-users list for a non-ORM
alternative, we decided to write our own Python object maker
middleware. This approach uses Python's psycopg module to initiate
calls to stored PL/pgSQL procedures and returns dynamically created
python objects.

A full length article, including source files (GPLv3), can be found
at:

http://campbell-lange.net/company/articles/dbwrapper/

This implementation allows us to keep writing complex database queries
in native SQL, with the additional benefit of returning ORM-like
python objects instead of psycopg's default 'list-of-lists'  data
structure.

Below is a small example of how we use this python wrapper:

»»» connection = psycopg.connect("dbname=test user=clw password=***")
»»» cursor = connection.cursor()
»»» cursor.execute("SELECT * FROM people WHERE id=%s, (1,))
»»» person = PyObject (cursor, "NewClass")
»»» person
»»» <objectmaker.NewClass object at 0xb7d8372c>
»»» print person.t_first_name
»»» sebastian
»»» print person.__dict__
»»» {'id':1, 't_first_name':'sebastian', 't_last_name':'ritter',
't_password':'password', 't_email':sebast...@test.com'}

Using the principles above, we have developed more complicated wrapper
methods to handle multi-row return sets (using generators), as well as
a grouping wrapper that returns multi-tiered objects.

We welcome any feedback or comments on this approach. It would also be
interesting to know why you would prefer to use an ORM over SQL
procedures. This will help fuel our internal debate as to which
approach is most suitable when dealing with complicated database
interactions.

Kindest regards,
Sebastian

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to