r/Python • • Dec 09 '10

new stand-alone web2py database abstraction layer

http://web2py.com/AlterEgo/default/show/272
18 Upvotes

82 comments sorted by

View all comments

2

u/wildmXranat Dec 09 '10

Even though web2py and I don't see eye to eye, their DAL is quite nice. In fact, I wanted to congratulate mdpierro and team on a great job.

Questions about the library:

How do you define and use it for hierarchical models ? Adjacency list or nested sets type of structures.

Can you hydrate the result sets as raw arrays and not objects to save on memory use ? <- this is a carry over from PHP Doctrine orm and it may not apply.

0

u/mdipierro Dec 09 '10

About hierarchical model web2py supports 1-to-1, 1-to-many and many-2-many no more no less that rmbds databases do. You can do for example.

  person=db.define_table('person',Field('name'))
  dog=db.define_table('dog',Field('name'),Field('ower',db.person))
  me=db.person.insert(name='Max')
  scooby=db.dog.insert(name='Scooby',owner=me)
  print scooby.owner.name
  for dog in db(dog.owner==me).select(): print dog.name
  for row in db(dog.owner==person.id).select(): print row.person.name, row.dog.name

The result sets in are not Objects in web2py as in SQLALchemy. They are Storage objects with are very similar to python dictionaries. They are parsed from the raw data but does not add too much memory overhead. They are parse to make sure the format of the data out is the same as the data in and independent on database engine.

Not sure I answered all your questions.