On Wed, Jan 21, 2009 at 2:00 AM, Jan Koprowski <[email protected]> wrote:
>
>
> What's the "problem" with SQLAlchemy ? My class (for example User)
> mapped by SQLAlchemy mapper doesn't have any additional methods. My
> tool is meta.Session.query and my code use this. So, when I move my
> data to my own binary file (for example) i must re implement whole
> controllers code to use something new because meta doesn't have any
> sense.
>
Why do you have to implement them into the User object? Why can't you
do this....
r = UserRepository()
u = User("Me")
r.add(u)
I just saved a user to a database, all of my domain code is in the
User class, all of my persistence code is in the UserRepository class,
which itself deals with meta.Session. If later I want to switch from
storing in a database to storing in a data file, I only need to make a
new class and have the controllers use this new one instead.
You can also have UserRepository inherit from a BaseRepository class
with the typical Add, Update, Delete, etc. methods so that you don't
have to rewrite them over and over again. More importantly, you can
have custom functions, like r.GetUsersWithExpiredPasswords(). Because
the SQLAlchemy query code is encapsulated into the repository's
GetUsersWithExpiredPasswords method, your controller still works fine
when you want to change to a datafile repository, so long as you have
reimplemented these custom queries using your new persistence
mechanism (which you would've done anyway, just in your User class).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---