|
| 1 | +###Data |
| 2 | +Data data::RelationalData |
| 3 | +{ |
| 4 | + Relational |
| 5 | + #{ |
| 6 | + default.PersonTable: |
| 7 | + 'id,firstName,lastName\n'+ |
| 8 | + '1,John,Doe\n'+ |
| 9 | + '2,Nicole,Smith\n'+ |
| 10 | + '3,Time,Smith\n'; |
| 11 | + }# |
| 12 | +} |
| 13 | + |
| 14 | + |
| 15 | +###Relational |
| 16 | +Database store::TestDB |
| 17 | +( |
| 18 | + Table PersonTable |
| 19 | + ( |
| 20 | + id INTEGER PRIMARY KEY, |
| 21 | + firstName VARCHAR(200), |
| 22 | + lastName VARCHAR(200) |
| 23 | + ) |
| 24 | +) |
| 25 | + |
| 26 | + |
| 27 | +###Pure |
| 28 | +import meta::pure::precisePrimitives::*; |
| 29 | + |
| 30 | +Class model::Person |
| 31 | +{ |
| 32 | + firstName: String[1]; |
| 33 | + lastName: String[1]; |
| 34 | +} |
| 35 | + |
| 36 | + |
| 37 | +function model::RelationModelQuery(): meta::pure::metamodel::relation::Relation<('first name':String, 'last name':String)>[1] |
| 38 | +{ |
| 39 | + model::Person.all() |
| 40 | + |
| 41 | + ->project(~[ |
| 42 | + 'first name': x | $x.firstName, |
| 43 | + 'last name': x | $x.lastName |
| 44 | + ]) |
| 45 | +->from( |
| 46 | + execution::RelationalMapping, |
| 47 | + execution::Runtime |
| 48 | + ) |
| 49 | +} |
| 50 | +{ |
| 51 | + testSuite_1 |
| 52 | + ( |
| 53 | + store::TestDB: |
| 54 | + Relational |
| 55 | + #{ |
| 56 | + default.PersonTable: |
| 57 | + 'id,firstName,lastName\n'+ |
| 58 | + '1,I\'m John,"Doe, Jr"\n'+ |
| 59 | + '2,Nicole,Smith\n'+ |
| 60 | + '3,Time,Smith\n'; |
| 61 | + }#; |
| 62 | + test_1 | RelationModelQuery() => (JSON) '[ {\n "first name" : "I\'m John",\n "last name" : "Doe, Jr"\n}, {\n "first name" : "Nicole",\n "last name" : "Smith"\n}, {\n "first name" : "Time",\n "last name" : "Smith"\n} ]'; |
| 63 | + ) |
| 64 | +} |
| 65 | + |
| 66 | +function model::RelationQuery(): meta::pure::metamodel::relation::Relation<(firstName:Varchar(200), lastName:Varchar(200))>[1] |
| 67 | +{ |
| 68 | + #>{store::TestDB.PersonTable}#->select( |
| 69 | + ~[ |
| 70 | + firstName, |
| 71 | + lastName |
| 72 | + ] |
| 73 | + )->from( |
| 74 | + execution::Runtime |
| 75 | + ) |
| 76 | +} |
| 77 | +{ |
| 78 | + testSuite_1 |
| 79 | + ( |
| 80 | + store::TestDB: |
| 81 | + Relational |
| 82 | + #{ |
| 83 | + default.PersonTable: |
| 84 | + 'id,firstName,lastName\n'+ |
| 85 | + '1,I\'m John,"Doe, Jr"\n'+ |
| 86 | + '2,Nicole,Smith\n'+ |
| 87 | + '3,Time,Smith\n'; |
| 88 | + }#; |
| 89 | + test_1 | RelationQuery() => (JSON) '[ {\n "firstName" : "I\'m John",\n "lastName" : "Doe, Jr"\n}, {\n "firstName" : "Nicole",\n "lastName" : "Smith"\n}, {\n "firstName" : "Time",\n "lastName" : "Smith"\n} ]'; |
| 90 | + ) |
| 91 | +} |
| 92 | + |
| 93 | +###Mapping |
| 94 | +Mapping execution::RelationalMapping |
| 95 | +( |
| 96 | + *model::Person: Relational |
| 97 | + { |
| 98 | + ~primaryKey |
| 99 | + ( |
| 100 | + [store::TestDB]PersonTable.id |
| 101 | + ) |
| 102 | + ~mainTable [store::TestDB]PersonTable |
| 103 | + firstName: [store::TestDB]PersonTable.firstName, |
| 104 | + lastName: [store::TestDB]PersonTable.lastName |
| 105 | + } |
| 106 | +) |
| 107 | + |
| 108 | + |
| 109 | +###Connection |
| 110 | +RelationalDatabaseConnection model::MyConnection |
| 111 | +{ |
| 112 | + store: store::TestDB; |
| 113 | + type: H2; |
| 114 | + specification: LocalH2 |
| 115 | + { |
| 116 | + testDataSetupSqls: [ |
| 117 | + 'Drop table if exists PersonTable;\nCreate Table PersonTable(id INT, lastName VARCHAR(200), firstName VARCHAR(200));\nInsert into PersonTable (id, lastName, firstName) values (1, \'John\', \'Doe\');\nInsert into PersonTable (id, lastName, firstName) values (2, \'Tim\', \'Smith\');\nInsert into PersonTable (id, lastName, firstName) values (3, \'Nicole\', \'Doe\');\n\n' |
| 118 | + ]; |
| 119 | + }; |
| 120 | + auth: DefaultH2; |
| 121 | +} |
| 122 | + |
| 123 | + |
| 124 | +###Runtime |
| 125 | +Runtime execution::Runtime |
| 126 | +{ |
| 127 | + mappings: |
| 128 | + [ |
| 129 | + execution::RelationalMapping |
| 130 | + ]; |
| 131 | + connections: |
| 132 | + [ |
| 133 | + store::TestDB: |
| 134 | + [ |
| 135 | + connection_1: model::MyConnection |
| 136 | + ] |
| 137 | + ]; |
| 138 | +} |
0 commit comments