source: mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/sqlAlchemyTables.vm @ 8411

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/xmi2sqlalchemy/trunk/src/main/resources/velocity/python/sqlAlchemyTables.vm@8411
Revision 8411, 2.1 KB checked in by mnagni, 8 years ago (diff)

created wrong table composition

  • Property svn:executable set to *
Line 
1##########################################################################
2## sqlAlchemyTables.vm
3## The form expects the following context attributes
4## tableModel - an instance of ClassModel class
5##########################################################################
6#macro(checkUseAlter $fk, $fkName, $relName)
7, use_alter=True, name='fk_${fkName}_${relName}'#end
8
9#macro( fk $foreignKey, $tableModel)
10#set ($fkName = ${foreignKey.tableModel.associatedClass.name.toLowerCase()})
11#set ($relName = ${foreignKey.parentAttributeName.toLowerCase().trim()})
12#if($foreignKey.associatedRelationship.isOneToOne() || !$foreignKey.associatedRelationship.useList)
13Column('${fkName}_${relName}_id', Integer, ForeignKey('${fkName}.id'#checkUseAlter($foreignKey, $fkName, $relName))),
14#else
15Column('${fkName}_${relName}', Integer, ForeignKey('${fkName}.id'#checkUseAlter($foreignKey, $fkName, $relName))),
16#end
17#end
18
19#macro( primaryKey $tableModel)
20#set ($tn = ${tableModel.associatedClass.name.toLowerCase()})
21${tab}Column('id', Integer, Sequence('${tn}_id_seq'), primary_key=True),
22#end
23
24#macro(checkNullable $simpleAttribute)
25#if($simpleAttribute.lowerBound != '0' && !$simpleAttribute.voidable)
26, nullable=False#else
27, nullable=True#end
28#end
29
30#macro( column $attribute)
31Column('${attribute.name}', ${vh.substituteDBType($attribute)} #checkNullable($attribute)),
32#end
33
34#macro( superColumn $tableModel)
35#foreach( $attribute in $tableModel.associatedClassModel.attributeModel)
36#if($attribute.subTypes)
37#foreach($sType in $attribute.subTypes)
38#set ($associatedCN = ${sType.associatedClass.name.toLowerCase().trim()})
39Column('_${attribute.name}_${associatedCN}_id', Integer, ForeignKey('${associatedCN}.id')),
40#end
41#end   
42#end
43#end
44
45#macro( table $tableModel)
46#set ($associatedCN = ${tableModel.associatedClass.name.toLowerCase()})
47${associatedCN}_table = Table('${associatedCN}', metadata,
48#primaryKey($tableModel)
49#foreach( $foreignKey in $tableModel.fk)
50#fk($foreignKey, $tableModel)
51#end
52#foreach( $attribute in $tableModel.attributeModel)
53#column($attribute)
54#end
55${tab}extend_existing=False,)
56#end
57${tab}#table($tableModel)
Note: See TracBrowser for help on using the repository browser.