The PEAK Developers' Center   PeakDatabaseApplications UserPreferences
 
HelpContents Search Diffs Info Edit Subscribe XML Print View
Version as of 2003-10-11 20:57:50

Clear message


1 Introduction

PEAK is an excellent platform for building Python database applications. Using a combination of several PEAK packages one can build powerful and flexible database applications quickly and easily.

2 First Steps

We should first discuss briefly the PEAK packages we'll be working with, primarily peak.binding, peak.naming, and peak.storage.

Peak's binding package provides powerful utilities for building component-based applications. This typically means that you create a top-level application class of some sort which instantiates the various component objects needed to accomplish the task at hand. With peak.binding these "component objects" will be able to find each other, most often by defining properties that "bind to" other objects in the hierarchy. Here's a quick example:

    1 from peak.api import binding, storage, config
    2 
    3 class aComponent(binding.Component):
    4     db = binding.Obtain(storage.ISQLConnection)
    5     def doWork(self):
    6         for row in self.db('select name, description from aTable'):
    7             print row.name, row.description
    8 
    9 class Application(binding.Component):
   10     db = binding.Obtain('sqlite:test.db', offerAs=[storage.ISQLConnection])
   11     mainComponent = binding.Make(aComponent)
   12 
   13     def run(self):
   14         self.mainComponent.doWork()
   15 
   16 if __name__ == '__main__':
   17     root = config.makeRoot()
   18     app = Application(root)
   19     app.run()

As subclasses of binding.Component, the Application and aComponent classes are capable of taking part in a component hierarchy. Such a hierarchy needs a "root" -- we use config.makeRoot() to create a component root object on line 17. On line 18 we instantiate an Application object, specifying that root will be its parent. When creating binding.Component-based objects by hand like this, one must always pass a parent object as the first parameter. When using binding within a class definition the parent object for the new component will be determined automatically.


PythonPowered
EditText of this page (last modified 2003-10-11 20:57:50)
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck