Sessions can use its db driver like so:

del db.sessions[0] -> clear table
del db.sessions[id] -> drop row
db.sessions[0] = db.sessions(**attrs) -> insert
db.sessions[id]  -> fetch
db.sessions[id] = attrs -> update (could contain lambdas for txn)

For example, if you wanted to make an FSDB db driver to store sessions
on disk:

simply implement:
__call__,__getitem__,__setitem__,__delitem__

Robin


On Jan 23, 9:14 am, Robin B <[email protected]> wrote:
> Now that db.table supports getitem,setitem,delitem, session can work
> by only using the new functions, then session db drivers do not need a
> query interface, and can be super simple.
>
> another shortcut:
>
> del db.posts[0] -> drop table
>
> I still think it is useful to get the default values:
> db.posts(**attrs)
>
> posts = db.posts
> posts[0]=posts(**attrs)
>
> Robin
>
> On Jan 23, 9:03 am, mdipierro <[email protected]> wrote:
>
> > can you elaborate on sesssion?
>
> > On Jan 23, 8:51 am, Robin B <[email protected]> wrote:
>
> > > This could be another possible shortcut for insert:
> > > db.posts[0] = attrs
> > > -> db.posts.insert(**attrs)
>
> > > then a session driver only requires:
> > > __getitem__,__setitem__,__delitem__
>
> > > Robin
>
> > > On Jan 23, 8:39 am, Robin B <[email protected]> wrote:
>
> > > > Session could make use of the new DAL syntax, globals.py:
>
> > > > rows=db(table.id==record_id).select()
> > > > -> row = table[record_id]
>
> > > > table._db(table.id==record_id).update(**dd)
> > > > -> table[record_id] = dd
>
> > > > Using this syntax session db drivers only need to implement:
>
> > > > insert(),__getitem__,__setitem__,__delitem__
>
> > > > For example MEMDB would not even need a query interface.
>
> > > > Robin
>
> > > > On Jan 23, 12:20 am, mdipierro <[email protected]> wrote:
>
> > > > > I just posted this in trunk following your suggestion.
>
> > > > > >>> db=SQLDB()
> > > > > >>> db.define_table('person',SQLField('name'))
> > > > > >>> db.person['name']
>
> > > > > <gluon.sql.SQLField object at 0x1327510>>>> 
> > > > > db.person.insert(name='Robin')
> > > > > 1
> > > > > >>> db.person.insert(name='Robin')
> > > > > 2
> > > > > >>> db.person[1]
>
> > > > > <SQLStorage {'update_record': <function <lambda> at 0x13ca930>, 'id':
> > > > > 1, 'name': 'Robin'}>>>> db.person[2]=dict(name='Tim')
> > > > > >>> db.person[1]=db.person[2]
> > > > > >>> db.person[1]
>
> > > > > <SQLStorage {'update_record': <function <lambda> at 0x13ca930>, 'id':
> > > > > 1, 'name': 'Tim'}>
>
> > > > > >>> del db.person[1]
>
> > > > > Beautiful, thank you!
>
> > > > > The lambda stuff requires more thought and work.
>
> > > > > Massimo
>
> > > > > On Jan 22, 10:39 pm, Robin B <[email protected]> wrote:
>
> > > > > > I was just reading UserDict and thought how getitem, setitem, 
> > > > > > delitem
> > > > > > could be added to db.Table for these:
>
> > > > > > person = db.person[person.id]
> > > > > > -> shortcut syntax for db(db.person.id==person.id).select()[0]
> > > > > > db.person[person.id] = db.person(age=lambda attrs: attrs.age+=1)
> > > > > > -> update a record without having to fetch it first
> > > > > > del db.person[person.id]
> > > > > > -> delete a record without having to fetch it first
>
> > > > > > There are more to be had:
>
> > > > > > len(db.posts) -> count()
>
> > > > > > for post in db.posts:
> > > > > >   post.update_record(...)
>
> > > > > > Robin
>
> > > > > > On Jan 22, 10:13 pm, mdipierro <[email protected]> wrote:
>
> > > > > > > Could you elaborate on dictmixin?
>
> > > > > > > SQLStorage already extends a dict. Which methods do you think are
> > > > > > > missing?
>
> > > > > > > Massimo
>
> > > > > > > On Jan 22, 9:03 pm, Robin B <[email protected]> wrote:
>
> > > > > > > > Simple queries could be generated from lists of filters, also 
> > > > > > > > simple
> > > > > > > > queries require fewer ()'s:
>
> > > > > > > > db(*programmatic_filters).select()
> > > > > > > > db(programmatic_filters).select()
> > > > > > > > db(db.person.last_name=='Obama',db.person.first_name=='Barack').select
> > > > > > > > ()
>
> > > > > > > > vs
>
> > > > > > > > db((db.person.last_name=='Obama')&
> > > > > > > > (db.person.first_name=='Barack')).select()
>
> > > > > > > > and
>
> > > > > > > > db(db.person.last_name=='Obama')(db.person.first_name=='Barack').select
> > > > > > > > ()
>
> > > > > > > > You have to iteratively build the query from the list, it would 
> > > > > > > > be
> > > > > > > > easier to just pass in the list with or without a * (splat).
>
> > > > > > > > The real benefit is that drivers that do not allow "|" (GAE, 
> > > > > > > > MEMDB)
> > > > > > > > could use trivial query parsers, which would make those drivers 
> > > > > > > > simple
> > > > > > > > to write and maintain.
>
> > > > > > > > > > person = db.person(party='Republican')
> > > > > > > > > > -> returns a person with default= values populated and 
> > > > > > > > > > **attrs set
> > > > > > > > > > person.first_name = 'John'
> > > > > > > > > > response.render(person=person)
> > > > > > > > > > -> the record can be printed on a page without inserting it 
> > > > > > > > > > in db
> > > > > > > > > > person.insert()
> > > > > > > > > > -> actually inserts the record, returns 1 for success, 0 
> > > > > > > > > > for failure,
> > > > > > > > > > updates person attrs
>
> > > > > > > > > Not convinced about this one.
>
> > > > > > > > The benefit here is that you have easy access to all the default
> > > > > > > > values without doing an insert, this become especially useful if
> > > > > > > > db.Field(default=lamda:foo(123)) becomes possible.
>
> > > > > > > > > > person = db.person[person.id]
> > > > > > > > > > -> shortcut syntax for 
> > > > > > > > > > db(db.person.id==person.id).select()[0]
>
> > > > > > > > > love this one
>
> > > > > > > > > > db.person[person.id] = db.person(age=lambda attrs: 
> > > > > > > > > > attrs.age+=1)
> > > > > > > > > > -> update a record without having to fetch it first
>
> > > > > > > > > this depends on the one above I am not convinced about. One 
> > > > > > > > > could do
> > > > > > > > > db.person[person.id].update_record(age=...)
>
> > > > > > > > db.person[person.id].update_record(age=...)
> > > > > > > > -> would require 2 db requests (select,update)
>
> > > > > > > >  db.person[person.id] = db.person(age=...)
> > > > > > > > -> would require 1 db request (update)
>
> > > > > > > > Since __setitem__(self,key,value)  maps to self[key] = value,
> > > > > > > > if implemented properly in the driver,
> > > > > > > > this eliminates the redundant db request.
>
> > > > > > > > > > del db.person[person.id]
> > > > > > > > > > -> delete a record without having to fetch it first
>
> > > > > > > > > love this one too
>
> > > > > > > > DictMixin could be used to implement a lot of functionality in 
> > > > > > > > the
> > > > > > > > driver:http://svn.python.org/view/python/trunk/Lib/UserDict.py?view=markup
>
> > > > > > > > Robin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to