samples/table2ddl.ysl2
changeset 0 76005e62091d
equal deleted inserted replaced
-1:000000000000 0:76005e62091d
       
     1 include yslt.yml2
       
     2 
       
     3 define operator "“(.*?)”" as call "idl2ddl" with "type", "%1";
       
     4 
       
     5 tstylesheet {
       
     6     const "idtype", "'INTEGER'";
       
     7 
       
     8     template "/" apply "module|class", 0;
       
     9 
       
    10     template "module" {
       
    11         param "namespace", "''";
       
    12         choose {
       
    13             when "$namespace=''"
       
    14                 apply "module|class", 0 with "namespace", "@name";
       
    15             otherwise
       
    16                 apply "module|class", 0 with "namespace", "concat($namespace,'_', @name)";
       
    17         }
       
    18     }
       
    19 
       
    20     template "class" {
       
    21         param "namespace", "''";
       
    22 
       
    23         choose {
       
    24             when "$namespace=''"    | CREATE TABLE «@name» (
       
    25             otherwise               | CREATE TABLE «$namespace»_«@name» (
       
    26         }
       
    27 
       
    28         if "count(attr[@name='id'])=0" |> id «$idtype»`if "count(attr)>0" > , `
       
    29 
       
    30         const "name", "@name";
       
    31         foreach "//class[class/@name=$name]" |> «@name»_fk «$idtype»,
       
    32 
       
    33         apply "attr";
       
    34 
       
    35         | );
       
    36 
       
    37         apply "class", 0 with "namespace", "$namespace";
       
    38     }
       
    39 
       
    40     template "attr" | «@name» “@type”`if "position() != last()" > , `
       
    41 
       
    42     function "idl2ddl" {
       
    43         param "type";
       
    44 
       
    45         choose {
       
    46             when "$type='string'"   > VARCHAR
       
    47             when "$type='long'"     > INTEGER
       
    48         }
       
    49     }
       
    50 }