>  I disagree that all queries belong in models. A complex query that needs 
> to be re-used in multiple places should go somewhere centralized (not 
> necessarily a model file, but perhaps a module). However, not all queries 
> need to be re-used. Furthermore, some queries are so simple, there is no 
> point in abstracting them into a re-usable function/class (e.g., selecting 
> all records and fields from a single table).
>  
>
> Apps grow in time and we never known if in a future we will need to reuse 
> a query,
>

True, but you can always abstract the query the first time you need to 
re-use it. It would be overkill to assume every query used anywhere will 
ultimately need to be re-used and therefore add the extra boilerplate up 
front, when in most cases it won't be needed.
 

> what happen if a client, in some moment decides that he don´t want to work 
> with the data of more than one year ago, but it should remain in the DB? 
> (Because so much data bothered and there is other software for data 
> analisys) Then will be necessary to change so simples queries one by one.
>

Well, in this specific case, you would just add a common filter to the 
table. More generally, though, I would say just re-factor when that happens 
rather than pre-maturely optimizing for every conceivable possible future 
need. Note, there is nothing special about queries in this regard -- this 
same logic would apply to any bit of controller code, which you can always 
imagine might need to be re-used somewhere.

I'm not saying you would never move queries to controllers or modules, and 
we could certainly add some examples (actually, I don't think table methods 
are even documented, so that would be a good place to raise this issue), 
but I reject the idea that queries never belong in controllers and that the 
book examples therefore represent bad practice. If we abstracted all the 
queries into centralized functions/methods, then we might have a different 
set of people complaining about all the extra boilerplate and unnecessary 
abstraction in web2py code.
 

> I do not really like to continue this discussion, from the beginning I 
> just wanted to comment on the reasons why some experienced web developers 
> I know have rejected web2py after reading only part of the manual.
>

I would be interested to hear more from them. Did they reject Django and 
Flask, whose documentation also shows examples with queries in controllers? 
I would also be interested to know if they thought that because the 
examples show queries in controllers, it is therefore technically 
impossible to create queries elsewhere.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to