Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add views example to Showcase #806

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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} ]';
}#;
}#
]
}
]
}
]
}
Loading