[PEAK] very elementary peak.model question

Doug Quale quale1 at charter.net
Tue Jul 13 15:55:14 EDT 2004


The lazy compute-once attributes provided by peak.binding are
invaluable.  What is the best way to get this behavior from
peak.model?

I have refactored some of my old code to use peak.binding instead of
an ad hack lazy attribute implementation I was using, and it works
very well.  As an example this is a fragment from an attempt to model
a SQL database for browsing:

    class DBSchema(binding.Component)

        def views(self):
            # query system catalogs for view names
            ...

        views = binding.Make(views)


But I think peak.model might be better suited for this because the
extra metadata that peak.model provides about the attributes could be
useful.  The old code I'm working with has each object load itself,
so at this point I'm not using peak data managers.

    class DBSchema(binding.Element):

        class views(model.Sequence):
            referencedType = model.String

            ???

Clearly I can write a simple get() method that will do the query after
checking to make sure that the value isn't already set, but that seems
too clunky to use with a framework as elegant as peak.

Maybe I'm thinking about this backwards.  It looks like when using a
peak DM the DM would manage this as part of creating model objects,
possibly by using storage.QueryLink().  Would it be best to not have
model objects load themselves?  If so, what would that look like?



More information about the PEAK mailing list