On Wed, Oct 13, 2010 at 2:31 PM, andrei <[email protected]> wrote:
> I'm against source code modification, want to know what is the best
If being a purist helps you, then it's cool. I hope it's not an excuse
to actually not read the source code.
> way of subclassing database.
Looking at the source code would help you anyway.
# web.db
_databases = {}
def database(dburl=None, **params):
"""Creates appropriate database using params.
Pooling will be enabled if DBUtils module is available.
Pooling can be disabled by passing pooling=False in params.
"""
dbn = params.pop('dbn')
if dbn in _databases:
return _databases[dbn](**params)
else:
raise UnknownDB, dbn
So, basically, if your DB class is found in web.db._databases, it will
be picked up and usable.
# web.db
def register_database(name, clazz):
"""
Register a database.
>>> class LegacyDB(DB):
... def __init__(self, **params):
... pass
...
>>> register_database('legacy', LegacyDB)
>>> db = database(dbn='legacy', db='test', user='joe', passwd='secret')
"""
_databases[name] = clazz
That's what you use to register it. You can subclass
``web.db.MySQLDB`` class to do what you need to do.
> Is the same connection used for all queries during the request?
I think it just asks the backend for a cursor, so I suppose it depends
on your particular backend.
--
Branko Vukelić
[email protected]
[email protected]
Check out my blog: http://www.brankovukelic.com/
Check out my portfolio: http://www.flickr.com/photos/foxbunny/
Registered Linux user #438078 (http://counter.li.org/)
I hang out on identi.ca: http://identi.ca/foxbunny
Gimp Brushmakers Guild
http://bit.ly/gbg-group
--
You received this message because you are subscribed to the Google Groups
"web.py" 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/webpy?hl=en.