Package install :: Package MoSTBioDat :: Package DataBase :: Package ForgetSQL2 :: Module forgetsql2 :: Class TableBuilder
[hide private]
[frames] | no frames]

Class TableBuilder

source code

object --+    
         |    
  Database --+
             |
            TableBuilder

Build Table subclasses by investigating database.

As with the Database class, remember to subclass in the DBConn instance in the _db class attribute.

The table builder will list all tables in the connected database and generate Table instances, one for each table.

In addition to figuring out column names and primary keys, the table builder will also guess foreign keys and add methods like get_something(), set_something() and get_somethings().

Instance Methods [hide private]
 
__init__(self, TableBase=<class 'install.MoSTBioDat.DataBase.ForgetSQL2.forgetsql2.Table'>)
Build tables using provided TableBase as a base class.
source code
 
all_tables(self)
Find all table names in active database.
source code
 
build_class(self, table_name)
Build the (empty) subclass for table_name.
source code
 
add_fields(self, table)
Find the fields and primary keys
source code
 
find_foreign(self, table)
Guess foreign keys.
source code
 
build_table(self, table_name)
Build a table class and find all fields.
source code
 
generate_foreign_methods(self, table)
Generate get/set-methods for foreign keys.
source code
 
generate_children_methods(self, table)
Generate get-methods for retrieving foreign key children.
source code
 
build_tables(self)
Fully generate the list of table classes.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Methods [hide private]

Inherited from Database (private): _execute, _iter_cursor, _query, _query_one

Class Variables [hide private]

Inherited from Database (private): _db

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, TableBase=<class 'install.MoSTBioDat.DataBase.ForgetSQL2.forgetsql2.Table'>)
(Constructor)

source code 

Build tables using provided TableBase as a base class.

If the parameter TableBase is not provided, Table will be used as a superclass.

If the base table does not have a valid _db attribute (ie. a DBConn connetion), it will be inherited from the TableBuilder class.

Overrides: object.__init__

all_tables(self)

source code 

Find all table names in active database.

Depending on the database type, this function will find the list of all table names and store them in self.table_names.

Table names ending in _seq are not included, but are placed in self.sequences instead.

build_class(self, table_name)

source code 

Build the (empty) subclass for table_name.

The generated class will have a Pythonish version of table_name as the official class name. For instance, the class for my_table will be MyTable.

find_foreign(self, table)

source code 

Guess foreign keys.

Basically a field fish_id is assumed a foreign key for the table fish - if it exists.

Note that build_table() must have been called on all tables first in order to compare foreign keys with primary keys.

generate_foreign_methods(self, table)

source code 

Generate get/set-methods for foreign keys.

The method names will be named like get_other() for the table class Other.

generate_children_methods(self, table)

source code 

Generate get-methods for retrieving foreign key children.

The method names will be named like get_others() for the table class Other.

build_tables(self)

source code 

Fully generate the list of table classes.

This is the main method which will retrieve all tables, generate the Table subclasses and finally generate foreign key methods.

The generated table classes will be available in self.tables using the SQL table name as a key.