Frameworks

mdipierro massimodipierro71 at gmail.com
Tue Oct 20 11:17:57 EDT 2009


On Oct 19, 9:01 am, flebber <flebber.c... at gmail.com> wrote:
> In short it seems to me that Django and Web2py include more "magic" in
> assisting oneself to create you web/application, whilst Pylons and
> Werkzueg leave more control in the users hands hopefully leading to
> greater expression and power.

it depends on how one defines "magic". web2py provides a DAL, not an
ORM. DAL expressions translate one-to-one into SQL statements in the
appropriate dialect (or GQL on GAE), no more, without additional
superstructure. The basic API are

   db.tablename.insert(filename=value)
   db(query).select(...)
   db(query).update(...)
   db(query).delete()
   db(query).count()

an example of query is

   query=(db.tablename.fieldname=='value')|(db.tablename.fieldname.like
('A%'))

which translates into

   WEHERE tablename.fieldname = 'value' OR tablename.fieldname LIKE 'A
%'

with the appropriate escaping for security or course.


Of course you can more complex expressions for nested selects, joins,
left joins, aggregates, etc. but the general principle stands. Here is
an example:


   db().select(db.table1.field1,db.table1.field2.sum
(),groupby=db.table1.field1)

and another (which does a nested select, a join and a left join):

   db((db.table1.field1.belongs(db(db.table2.field2.id>0)._select
(db.table2.field3)))&
      (db.table1.field4==db.table3.field5)).select
(
          db.table1.ALL,db.table2.field6,
          left=db.table4.on
(db.table4.field6==db.table1.field7),
          orderby=db.table1.field8)






More information about the Python-list mailing list