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

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

First Import

  • Property svn:executable set to *
Line 
1## sqlAlchemyTables.vm
2
3#macro( attributeType $attribute)
4#if($attribute.enumLike)
5${attribute.associatedClass.name}.db_type()#elseif($attribute.hasMultiplicity())
6ARRAY(${attribute.associatedClass.name})#else
7${attribute.associatedClass.name}(#if($attribute.lenght > 0)${attribute.lenght}#end)#end
8#end
9
10#macro( column $simpleAttribute)
11Column('${simpleAttribute.name}', #attributeType($simpleAttribute) #checkNullable($simpleAttribute.lowerBound)),
12#end
13
14#macro( inheritanceColumn $tableModel)
15        #foreach( $parent in $tableModel.inherited)
16                #set ($pn = ${parent.associatedClass.name.toLowerCase()})
17                #set ($tn = ${tableModel.associatedClass.name.toLowerCase()})
18${tab}Column('${tn}_${pn}_id', Integer),#end
19        #if($tableModel.inherited && $tableModel.inherited.size() > 0)
20        #foreach( $parent in $tableModel.inherited)
21                #set ($pn = ${parent.associatedClass.name.toLowerCase()})
22                #set ($tn = ${tableModel.associatedClass.name.toLowerCase()})
23ForeignKeyConstraint(['${tn}_${pn}_id'],
24        ['${pn}.${pn}_id']),#end
25        #end
26#end
27
28#macro( fk $foreignKey, $tableModel)
29#set ($fkName = ${foreignKey.tableModel.associatedClass.name.toLowerCase()})
30Column('${fkName}_${foreignKey.parentAttributeName}', Integer, ForeignKey('${fkName}.${fkName}_id')),
31#end
32
33#macro( table $tableModel)
34#set ($associatedCN = ${tableModel.associatedClass.name.toLowerCase()})
35${associatedCN}_table = Table('${associatedCN}', metadata,
36${tab}Column('${associatedCN}_id', Integer, Sequence('${associatedCN}_id_seq'), primary_key=True),
37#foreach( $foreignKey in $tableModel.fk)
38${tab}#fk($foreignKey, $tableModel)
39#end
40#foreach( $simpleAttribute in $tableModel.am)
41${tab}#column($simpleAttribute)
42#end
43#if($tableModel.hasChildren)
44${tab}Column('${tableModel.associatedClass.name.toLowerCase()}_type', String(30), nullable=False),
45#end
46#inheritanceColumn($tableModel)
47${tab}extend_existing=False,)
48#end
49
50#table($tableModel)
51 
52 
Note: See TracBrowser for help on using the repository browser.