Step 1: Database Definition

The first step in using the eXtremeDB Python API is to define the classes that you’ll want to manage in the eXtremeDB database. The eXtremeDB Python wrapper has the mcocomp runtime compiled in, so the database schema can be defined in the form of text, just like a regular .mco file. For example, the following is a simple database schema defined with a Python string:

     
    >>> schema = '''
    #define uint4     unsigned<4>
    declare database opendb;
    class myclass  {
    uint4 i4;
    };
    '''
    >>>
     

To process and load this schema, call the load_dictionary() method:

     
    >>> dict = exdb.load_dictionary(schema)
    >>> dict
    <eXDB.Dictionary object at 0x1006e0790>
    >>>
     

The full load_dictionary() method signature is quite complicated as it includes all the options for the mcocomp schema compiler:

 
    def load_dictionary(schema, nosort=False, dumpxml=False, genhpp=False, 					
                gencs=False, genjava=False, outDir='.', 						
                csNamespace='eXtremeDB', javaPackage='eXtremeDB', 
                cmode1=False, 						genXmlMethods=False, genSql=False, 
                							largeDatabase=False, wcharSize=2, use_prefix=False, 
                include_dir='.', 							compact=False, persistent=False, 
                							transient=True, suppress_api=False, 							debug=False):
 

Only the ‘schema’ argument itself is mandatory; all other arguments are optional and take the defaults indicated above. For details on defining the database schema please refer to the C API DDL page.