[storm] proposal for improvement
Gerdus van Zyl
gerdusvanzyl at gmail.com
Wed Jun 10 16:18:07 BST 2009
On Tue, Jun 9, 2009 at 3:56 AM, Gustavo Niemeyer<gustavo at niemeyer.net> wrote:
>
> Have you thought about what kind of parameters we could add that would
> make it possible to build that kind of extension on top of Storm,
> without necessarily introducing the knowledge of all extensions into
> Storm itself?
>
> In other words, can we add some special "decorator" syntax for the
> columns, that will aid that kind of scenario without requiring all the
> knowledge of which attributes are there to live inside Storm itself?
>
> I'm certainly keen on offering the extensibility aspect in Storm, so
> that we can help that kind of use case.
>
A suggestion I have made once before is the following:
change the variable class init to:
def __init__(self, value=Undef, value_factory=Undef, from_db=False,
allow_none=True, column=None, event=None, validator=None,
validator_object_factory=None,
validator_attribute=None,**otherkwargs):
so adding the **otherkwargs so that sending unknown arguments does not
cause exception.
With that simple change one can then add extra keyword arguments to
the column and be able to get it out again. Example below
(http://python.pastebin.com/m54af21d3):
from storm.info import get_cls_info
from storm.locals import *
class Person(object):
__storm_table__ = "person"
id = Int(primary=True)
name = Unicode(strleng=16)
@classmethod
def column_args(cls):
#populate _storm_columns
get_cls_info(cls)
theargs = {}
for prop in cls._storm_columns:
name = prop._detect_attr_name(Person)
theargs[name] = prop._variable_kwargs
return theargs
database = create_database("sqlite:")
store = Store(database)
store.execute("""CREATE TABLE person
(id INTEGER PRIMARY KEY, name VARCHAR)""")
print Person.column_args()
#>>{'id': {'value_factory': Undef, 'value': Undef}, 'name':
{'value_factory': Undef, 'value': Undef, 'strleng': 16}}
~Gerdus
More information about the storm
mailing list