Creating and Modifying Database Objects in Python

To create an object (i.e. insert a record into the database) use the Connection method new() which takes a class name as argument. It returns a Python object which corresponds to the one created in the database. The type for the python object is dynamically defined from the schema when the database is created. And note that all database access must be within the scope of a transaction. For example:

     
    >>>con.startTransaction()
    >>> o = con.new(“myclass”)
     

The variable ‘o’ is a python object of type “myclass” (as defined in the schema). We can now view its fields by typing the variable name:

 
    >>> o
    <eXtremeDB object:myclass>.{'i4':0L}
     

We can assign a field’s value, for example:

 
    >>> o.i4=10
    >>> o
    <eXtremeDB object:myclass>.{'i4':10}
     

Finally, commit the transaction to complete the operation:

 
    >>> con.commit()
     

Date, Time and Datetime Fields

Please refer to the Datetime FIelds page for a detailed description of the eXtremeDB date, time and datetime database field types. The Python APIs for determining precision and accessing date, time and datetime fields are described in the Managing Datetime Fields in Python page.