The PEAK Developers' Center   Diff for "PeakDatabaseApplications" UserPreferences
 
HelpContents Search Diffs Info Edit Subscribe XML Print View
Ignore changes in the amount of whitespace

Differences between version dated 2003-11-12 01:43:21 and 2005-03-08 15:03:29 (spanning 5 versions)

Deletions are marked like this.
Additions are marked like this.

= Introduction =
 
Note: this page is an incomplete draft; please see IntroToPeak for a tutorial.
 
 
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.
 
= First Steps: Binding and Naming =

    worker = binding.Make(Worker)
 
    def run(self):
        storage.beginTransaction(self)
        self.worker.doWork()
        storage.commitTransaction(self)
 
if __name__ == '__main__':
    from peak.api import config

    app.run()
}}}
 
As subclasses of `binding.Component`, the `Application` and `Worker` classes are capable of taking part in a component hierarchy. Such a hierarchy needs a "root" object at its base -- we use `config.makeRoot()` to create a component root object on line 18. On line 19 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 bindings within a class definition (as done on lines 4, 10, and 11) the parent object for the new component will be supplied automatically, if needed.
As subclasses of `binding.Component`, the `Application` and `Worker` classes are capable of taking part in a component hierarchy. Such a hierarchy needs a "root" object at its base -- we use `config.makeRoot()` to create a component root object on line 20. On line 21 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 bindings within a class definition (as done on lines 4, 10, and 11) the parent object for the new component will be supplied automatically, if needed.
 
This small example is already a working database application. It opens a connection to a [http://www.sqlite.org/ SQLite] database file, runs a query against a table, and prints the results. It also demonstrates one of the most useful aspects of the binding package: the ability to create an object once and make use of it in another part of the application. In database applications you usually want a single connection to a database server which will be shared throughout the application. Without binding one would have to either create the connection object and pass it to every new object that needed it, or provide it to the rest of the application using a singleton mechanism of some kind.
 

PythonPowered
ShowText of this page
EditText of this page
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck