On Tuesday 23 February 2010 10:26:20 am Koen Deforche wrote:
> Hey Mike,
>
> 2010/2/22 Mike Teehan <[email protected]>:
> > Hello everyone. Just trying to get my head around the new
Wt::Dbo::Dbo
> > class... Basically, this lets you move some of your code into the db
> > object's class, right?
>
> *
>
> > Example:
> > I have a getUserList() function that queries the db to find all the
users
> > (class User) who can log in. This function lives in the login code.
> > Once I switch to deriving my User from Dbo::Dbo, I can then move
> > getUserList() to be part of the User class, better sharing the
> > functionality.
> >
> > If this is the case, it looks like I have a bit of refactoring to do.
>
> Yes, that is what it is meant for, although the particular example
> getUserList() sounds like it is a static method which will not have
> access to the session(), it is only associated with a particular user.
> The standard use case would be like :
All this became very apparent as I toyed with class changes last night.
In your experience do you think it would be better to make it a static
member (I don't like static stuff... it scares me) or should I perhaps
make a singleton (per session) UserDB class that can manage that stuff?
Its seems in the Blog example that you just put most of the db stuff
right into the view code. Quick and dirty?
> Posts User::latestPosts(int count) const
> {
> if (session())
> return session()->find<Post>
> ("where author_id = ? and state = ? "
> "order by date desc "
> "limit ?")
> .bind(id())
> .bind(Post::Published)
> .bind(count);
> else
> return Posts();
> }
>
> Note that session() may be 0 for an object that is not yet associated
> with a session.
This clarifies things a lot. Straight out of the Blog example... I see it in
there now.
> Regards,
> koen
>
Thanks,
Mike
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest