#! /usr/bin/env python
'''
A sample Pythonic OO-RDB Model
(re-expressing testPackages/AuthorBooks/model_AuthorBooks.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'] = 2
AString.defaults['width'] = 40
Association.defaults['delete']=['nullify', 'nullify']
Entity.defaults['properties'] = [
APrimaryKey('id', isClassProperty=0, isRequired=1, doc='PK')
]
##
_connDict = {'database': 'AUTHOR_BOOKS'}
_connDict = {'database': 'AUTHOR_BOOKS', 'host':'localhost','user':'postgres','password':''}
model = Model('AuthorBooks',adaptorName='Postgresql',
connDict=_connDict)
model.doc = ' ... '
model.version='0.1'
model.entities = [
#
Entity('Book',
properties=[ APrimaryKey('id', isClassProperty=1,
columnName='id'),
AString('title', isRequired=1, columnName='title'),
AFloat('price', externalType='NUMERIC', width=0,precision=0),
AForeignKey('FK_Writer_Id', isClassProperty=1),
],
),
Entity('Writer',
properties=[ AString('lastName',isRequired=1, width=30,
displayLabel='Last Name', ),
AString('firstName',
displayLabel='First Name', ),
AInteger('age', displayLabel='Age', ),
ADateTime('birthday', usedForLocking=0,
displayLabel='birthday', ),
]
),
]
#---
model.associations=[
Association('Book', 'Writer',
relations=['author', 'books'],
delete=['nullify', 'cascade'],
keys=['FK_Writer_Id', 'id']),
Association('Writer', 'Writer',
relations=['pygmalion', None],
delete=['nullify', None],
keys=['FK_Writer_id', 'id']),
]
model.build()
|