Personal tools
     DOCUMENTATION

rPath Appliance Platform:Plugin Database Tables

From rPath Wiki

Jump to: navigation, search

Developers can create and define database tables as necessary for an rPath Appliance Platform plugin.

Each plugin inherits methods (self.setPropertyValue, self.getPropertyValue, self.getPropertyDict) from the rAAWebPlugin base class. If the plugin only needs a way to set and retrieve key-value pairs, additional database tables may not be necessary.

If the plugin requires a different data storage system than is provided by the property methods, these tables should follow the naming convention plugin_project_tablename where project is replaced by a string identifying the plugin author or organization, and tablename is replaced by a unique identifier for the particular table. For example, the table used to store data used in configuring services is named plugin_rpath_Services. For consistency, use the plugin name for the tablename portion of the table name.

To create a table, define a class in the Python code that inherits from raa.db.database.DatabaseTable or one of its subclasses such as raa.db.database.KeyedTable or raa.db.data.GenericDataTable.

Either your database class or one of your super-classes must have a createSQL field that defines how the table is created. One of the super-classes will likely contain all the basic functions for inserting values into and selecting values from the table, though you may use your own table class to create convenient methods specific to the purpose of the table.

Reference a table from the web component of your plugin by creating a field named tableClass. The value of the field can be one of two things:

  • The table class itself with your plugin referring to an instance of the table using the expression self.table
  • The value of tableClass as a dictionary whose keys are strings and whose values are table classes, with instances of these tables can referenced in the plugin by accessing the attribute with the same name as the corresponding key in the dictionary.