Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #26513

Object Models - decoupling data access - good examples ?

From shearichard@gmail.com
Newsgroups comp.lang.python
Subject Object Models - decoupling data access - good examples ?
Date 2012-08-04 17:04 -0700
Organization http://groups.google.com
Message-ID <ebb88ade-7598-46b1-8fb6-fd7f7430b296@googlegroups.com> (permalink)

Show all headers | View raw


I'm interested in best practice approaches to : decoupling data access code from application code; and translations between database structures and domain objects.

For some time I've done database access by in a particular way and while I think it's OK it's not very pythonic so I'd be interested in hearing of other approaches - even better if there are open source examples whose code might be read.

I should say I'm talking relational database here and, for various reasons, ORMs are not involved.

So this is what I do (in a one class project call 'bar') in order to allow objects of type foo to be fetched/inserted/updated


bar/foo.py
bar/bardb/bardbConnection.py
bar/bardb/BusinessLogic/fooManager.py
bar/bardb/BusinessObject/foo.py
bar/bardb/DataAccess/fooDB.py

And this is what they actually do :


bar/foo.py
The class as the outside world knows it 

bar/bardb/bardbConnection.py
Manages database connection

bar/bardb/BusinessLogic/fooManager.py
Exposes methods used by bar/foo.py such as 'save'/'update' etc and implements necessary validation etc

bar/bardb/BusinessObject/foo.py
A collection of getters/setters which does any translation between types necessary on the way to/from the rdbms

bar/bardb/DataAccess/fooDB.py
Implements the actual SQL necessary for the relevant interactions with the database

As I say this works OK for me but I'd be interested to hear of what others do.

Thanks

Richard.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Object Models - decoupling data access - good examples ? shearichard@gmail.com - 2012-08-04 17:04 -0700
  Re: Object Models - decoupling data access - good examples ? Roy Smith <roy@panix.com> - 2012-08-04 21:17 -0400
    Re: Object Models - decoupling data access - good examples ? shearichard@gmail.com - 2012-08-04 20:26 -0700
      Re: Object Models - decoupling data access - good examples ? Roy Smith <roy@panix.com> - 2012-08-05 09:04 -0400
      Re: Object Models - decoupling data access - good examples ? Adam Tauno Williams <awilliam@whitemice.org> - 2012-08-07 09:00 -0400
      RE: Object Models - decoupling data access - good examples ? "Sells, Fred" <fred.sells@adventistcare.org> - 2012-08-07 15:46 +0000

csiph-web