Skip to content

Commit

Permalink
add views example to intergate mapping showcase (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
haroonsherjan committed Apr 15, 2024
1 parent 0aa632f commit a060043
Showing 1 changed file with 133 additions and 127 deletions.
260 changes: 133 additions & 127 deletions showcases/data/End To End Examples/Integrate Mappings/code.pure
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
###Pure
Class com::entity::LegalEntity
{
entityId: String[1];
name: String[1];
}

Class com::trade::Trade
{
id: String[1];
value: Integer[1];
}

Association com::trade::Trade_LegalEntity
###Data
Data com::entity::EntityData
{
client: com::entity::LegalEntity[1];
trades: com::trade::Trade[*];
Relational
#{
Entity.LegalEntity:
'ENTITY_ID,name\n'+
'abc,Entity1\n'+
'def,Entity2\n';
}#
}


Expand All @@ -41,22 +34,142 @@ Database com::entity::EntityDatabase
ENTITY_ID VARCHAR(32) PRIMARY KEY,
name VARCHAR(32) NOT NULL
)

View LegalEntity_View
(
ENTITY_ID: Entity.LegalEntity.ENTITY_ID PRIMARY KEY,
name: Entity.LegalEntity.name PRIMARY KEY
)
)
)


###Service
Service com::trade::ServiceSimpleProject
{
pattern: '/trade/simpleJoinProjectService';
owners:
[
'user1',
'user2'
];
documentation: '';
autoActivateUpdates: true;
execution: Single
{
query: |com::trade::Trade.all()->project(
[
x: com::trade::Trade[1]|$x.value,
x: com::trade::Trade[1]|$x.client.name
],
[
'Value',
'Client/Name'
]
);
mapping: com::trade::TradeWithLegalEntityMapping;
runtime: com::trade::AlternativeTradeRuntime;
}
testSuites:
[
testSuite_1:
{
data:
[
connections:
[
com::trade::TradeConnection:
Relational
#{
Trade.Trade:
'id,value,ENTITY_ID_FK\n'+
'1,100,abc\n'+
'2,200,def\n';
}#,
com::trade::TradeConnection:
DataspaceTestData
#{
com::entity::EntityDataSpace
}#
]
]
tests:
[
test_1:
{
serializationFormat: PURE_TDSOBJECT;
asserts:
[
assertion_1:
EqualToJson
#{
expected:
ExternalFormat
#{
contentType: 'application/json';
data: '[ {\n "Value" : 100,\n "Client/Name" : "Entity1"\n}, {\n "Value" : 200,\n "Client/Name" : "Entity2"\n} ]';
}#;
}#
]
}
]
}
]
}


###DataSpace
DataSpace com::entity::EntityDataSpace
{
executionContexts:
[
{
name: 'default';
mapping: com::entity::LegalEntityMapping;
defaultRuntime: com::entity::EntityRuntime;
testData:
Reference
#{
com::entity::EntityData
}#;
}
];
defaultExecutionContext: 'default';
}


###Pure
Class com::entity::LegalEntity
{
entityId: String[1];
name: String[1];
}

Class com::trade::Trade
{
id: String[1];
value: Integer[1];
}

Association com::trade::Trade_LegalEntity
{
client: com::entity::LegalEntity[1];
trades: com::trade::Trade[*];
}


###Mapping
Mapping com::entity::LegalEntityMapping
(
*com::entity::LegalEntity: Relational
{
~primaryKey
(
[com::entity::EntityDatabase]Entity.LegalEntity.ENTITY_ID
[com::entity::EntityDatabase]Entity.LegalEntity_View.ENTITY_ID
)
~mainTable [com::entity::EntityDatabase]Entity.LegalEntity
entityId: [com::entity::EntityDatabase]Entity.LegalEntity.ENTITY_ID,
name: [com::entity::EntityDatabase]Entity.LegalEntity.name
~mainTable [com::entity::EntityDatabase]Entity.LegalEntity_View
entityId: [com::entity::EntityDatabase]Entity.LegalEntity_View.ENTITY_ID,
name: [com::entity::EntityDatabase]Entity.LegalEntity_View.name
}
)

Expand Down Expand Up @@ -86,26 +199,6 @@ Mapping com::trade::TradeWithLegalEntityMapping
)


###DataSpace
DataSpace com::entity::EntityDataSpace
{
executionContexts:
[
{
name: 'default';
mapping: com::entity::LegalEntityMapping;
defaultRuntime: com::entity::EntityRuntime;
testData:
Reference
#{
com::entity::EntityData
}#;
}
];
defaultExecutionContext: 'default';
}


###Connection
RelationalDatabaseConnection com::entity::EntityConnection
{
Expand Down Expand Up @@ -168,90 +261,3 @@ SingleConnectionRuntime com::trade::AlternativeTradeRuntime
];
connection: com::trade::TradeConnection;
}


###Data
Data com::entity::EntityData
{
Relational
#{
Entity.LegalEntity:
'ENTITY_ID,name\n'+
'abc,Entity1\n'+
'def,Entity2\n';
}#
}


###Service
Service com::trade::ServiceSimpleProject
{
pattern: '/trade/simpleJoinProjectService';
owners:
[
'user1',
'user2'
];
documentation: '';
autoActivateUpdates: true;
execution: Single
{
query: |com::trade::Trade.all()->project(
[
x: com::trade::Trade[1]|$x.value,
x: com::trade::Trade[1]|$x.client.name
],
[
'Value',
'Client/Name'
]
);
mapping: com::trade::TradeWithLegalEntityMapping;
runtime: com::trade::AlternativeTradeRuntime;
}
testSuites:
[
testSuite_1:
{
data:
[
connections:
[
com::trade::TradeConnection:
Relational
#{
Trade.Trade:
'id,value,ENTITY_ID_FK\n'+
'1,100,abc\n'+
'2,200,def\n';
}#,
com::trade::TradeConnection:
DataspaceTestData
#{
com::entity::EntityDataSpace
}#
]
]
tests:
[
test_1:
{
serializationFormat: PURE_TDSOBJECT;
asserts:
[
assertion_1:
EqualToJson
#{
expected:
ExternalFormat
#{
contentType: 'application/json';
data: '[ {\n "Value" : 100,\n "Client/Name" : "Entity1"\n}, {\n "Value" : 200,\n "Client/Name" : "Entity2"\n} ]';
}#;
}#
]
}
]
}
]
}

0 comments on commit a060043

Please sign in to comment.