How to create and manage a database with genro.

First of all a database description must be provided using the class GnrDataStructure?. In our example we want to create a simple database containing movies, directors and dvd. In order to do this we have to write a mixin class and define one single method called configure. In the configure method we describe our database.

In this first part we define a package, a logical structure that represents a set of table. The instruction package add a package element. In our model must be defined at least one package as root element.

class DvdCatalog(object):

    def configure(self):
        
        pkg_ctlg = self.structdata.package('ct',
                                            comment='My movie catalog',
                                            name_short='Ctlg',
                                            name_long='Video Catalog',
                                            name_full='John's video catalog')

Then we start adding tables to the package: director, movie, dvd.

director = pkg_ctlg.table('director', name_short='Dir',name_long='Director', name_full='Director table')

For each table we can add columns with the functions column, intColumn, dateColumn, etc. Table's primary key is set with the function pkey.

dir_id = director.intColumn('id')
director.pkey('id')

A column can be related to another with the method ralate.

movie.column('director', name_short='Dir',name_long='Director').relate(dir_id)