#! /usr/bin/env python
'''
A sample Pythonic OO-RDB Model
(re-expressing testPackages/StoreEmployees/model_StoreEmployees.xml) --
A PyModel must define a global variable called 'model', that is of type Model
'''
from Modeling.PyModel import *
##
# Set preferred defaults for this model (when different from
# standard defaults, or if we want to make things explicit)
AFloat.defaults['precision'] = 10
AFloat.defaults['scale'] = 10
AString.defaults['width'] = 30
Association.defaults['delete']=['nullify', 'nullify']
Entity.defaults['properties'] = [
APrimaryKey('id', isClassProperty=0, isRequired=1, doc='Primary key!')
]
##
_connDict = {'database': 'STORE_EMPLOYEES'}
model = Model('StoreEmployees',adaptorName='Postgresql',
connDict=_connDict)
model.doc = ' ... '
model.version='0.1'
model.entities = [
#
Entity('Store',
properties=[ AString('corporateName', isRequired=1), ],
),
Entity('Employee',
moduleName='Employees',
properties=[ AString('lastName',isRequired=1,usedForLocking=1,
width=20),
AString('firstName', isRequired=1, width=50,
usedForLocking=1),
]
),
Entity('SalesClerk', parent='Employee',
moduleName='Employees',
properties=[ AString('storeArea', width=20) ]
),
Entity('Executive', parent='Employee',
moduleName='Employees',
properties=[ AString('officeLocation', width=5) ]
),
Entity('Address',
properties=[ AString('street', width=80),
AString('zipCode', width=10),
AString('town'),
]
),
Entity('Mark',
properties=[ AInteger('month', isRequired=1),
AInteger('mark', isRequired=1),
]
),
Entity('Holidays',
properties=[ ADateTime('startDate', isRequired=1),
ADateTime('endDate', isRequired=1),
]
),
]
model.associations=[
Association('Mark', 'Executive',
relations=['executive', 'marks'],
delete=['nullify', 'cascade'],
keys=['FK_Executive_id', 'id']),
Association('Address', 'Employee',
relations=['toEmployee', 'toAddresses'],
delete=['deny', 'cascade'],
keys=['fkEmployeeId', 'id'],
),
Association('Employee', 'Store',
relations=['toStore', 'employees'],
delete=['nullify', 'deny'],
keys=['fkStoreId', 'id']),
Association('Holidays', 'Employee',
relations=[None, 'holidays'],
delete=[None, 'cascade'],
keys=['fkEmployeeId', 'id']),
]
model.build()
model=model.component
|