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

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

Works fine but I have to find a way to initialize the python classes attributes

  • 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
7#macro( attributeType $attribute)
8#if(!$attribute.associatedType.associatedClass.name.equalsIgnoreCase('boolean')
9&& ($attribute.associatedType.isCodeList() || $attribute.associatedType.isEnumeration()))
10${attribute.associatedType.associatedClass.name}.db_type()#elseif($attribute.hasMultiplicity())
11ARRAY(#substituteDBType(${attribute.associatedType.associatedClass.name}))#else
12#substituteDBType(${attribute.associatedType.associatedClass.name})#end
13#end
14
15#macro( column $attribute)
16Column('${attribute.name}', #attributeType(${attribute}) #checkNullable($attribute)),
17#end
18
19#macro(checkUseAlter $fk, $fkName, $relName)
20#if($fk.useAlter)
21, use_alter=True, name='fk_${fkName}_${relName}'#end
22#end
23
24#macro( fk $foreignKey, $tableModel)
25#set ($fkName = ${foreignKey.tableModel.associatedClass.name.toLowerCase()})
26#set ($relName = ${foreignKey.parentAttributeName.toLowerCase()})
27#if($foreignKey.associatedRelationship.isOneToOne() || !$foreignKey.associatedRelationship.useList)
28Column('${fkName}_${relName}_id', Integer, ForeignKey('${fkName}.id'#checkUseAlter($foreignKey, $fkName, $relName))),
29#else
30Column('${fkName}_${relName}', Integer, ForeignKey('${fkName}.id'#checkUseAlter($foreignKey, $fkName, $relName))),
31#end
32#end
33
34#macro( primaryKey $tableModel)
35#set ($tn = ${tableModel.associatedClass.name.toLowerCase()})
36${tab}Column('id', Integer, Sequence('${tn}_id_seq'), primary_key=True),
37##if($tableModel.inherited && $tableModel.inherited.size() > 0)
38        ##foreach( $parent in $tableModel.inherited)
39                ##set ($pn = ${parent.associatedClass.name.toLowerCase()})
40                ##${tab}Column('_${pn}', Integer, ForeignKey('${pn}.${pn}_id')),#end
41##end
42#end
43
44#macro(checkNullable $simpleAttribute)
45#if($simpleAttribute.lowerBound != '0' && !$simpleAttribute.voidable)
46, nullable=False#else
47, nullable=True#end
48#end
49
50
51
52#macro( table $tableModel)
53#set ($associatedCN = ${tableModel.associatedClass.name.toLowerCase()})
54${associatedCN}_table = Table('${associatedCN}', metadata,
55#primaryKey($tableModel)
56#foreach( $foreignKey in $tableModel.fk)
57${tab}#fk($foreignKey, $tableModel)
58#end
59#foreach( $attribute in $tableModel.attributeModel)
60${tab}#column($attribute)
61#end
62${tab}extend_existing=False,)
63#end
64
65#table($tableModel)
66 
67 
Note: See TracBrowser for help on using the repository browser.