@sap/cds/common
Why use it?
@sap/cds/common을 쓰는 이유는 간결하고 이해하기 쉬운 모델로서 작용하기 때문이다.
뿐만 아니라, 모든 Application 간의 상호 운용성을 촉진하며,
실제 Application에서 입증되기도 하였고,
이는 진입 장벽이 최소화/간소화된 데이터 모델이기에 가능하다.
또한 최적화된 구면 및 런타임 성능을 지녔으며,
현지화된 코드 목록과 값에 대한 도움말을 자동으로 지원해준다.
Aspect를 사용함으로써 활용도를 확장시키기도 한다.
Common Reuse Aspects
cuid
entity Foo : cuid {...}
entity Foo {
key ID : UUID;
...
}
cuid를 사용하게 되면 UUID로 지정해둔 key ID가 자동으로 생성되는 편리함을 가질 수 있다.
managed
entity Foo : managed {...}
entity Foo {
createdAt : Timestamp @cds.on.insert : $now;
createdBy : User @cds.on.insert : $user;
modifiedAt : Timestamp @cds.on.insert : $now @cds.on.update : $now;
modifiedBy : User @cds.on.insert : $user @cds.on.update : $user;
...
}
managed를 사용하면 위와 같이, 생성자와 수정자, 그에 대한 시간 관리에 관한 정보를 포착하는 요소를 추가할 수 있다.
참고로 ModifiedAt이나 ModifiedBy는 각 행이 수정될 때마다 설정 된다.
즉, CREATE 작업 중에도 설정됨을 알아두자.
temporal
entity Contract : temporal {...}
temporal은 validForm과 validTo를 entity에 추가한다.
그리고 임시 데이터에대한 CDS Compiler와 런타임의 내장 지원을 연결하는 Tag 주석을 추가한다.
즉, 시간과 관련된 정보들을 기록할 수 있다고 이해할 수 있다.
sap.common.TextsAspect
aspect sap.common.TextAspect {
key locale: sap.common.Locale;
}
sap.common.TextsAspect는 지역화된 요소를 적용시키기 위해 사용한다(?)
Common Reuse Types
Country
[ CAP ] Associations
Associations Unmanaged Associations entity Employees { address : Association to Addresses on address.ID = address_ID; address_ID : Integer; //> foreign key } entity Addresses { key ID : Integer; } entity Addresses에 있는 key ID를 Integer로 설정한
pythonchoboman.tistory.com
type Country : Association to sap.common.Countries;
using { country } from '@sap/cds/common';
entity Addresses {
street : String;
town : String;
country : Country // using reuse type
}
CREATE TABLE Addresses (
street NVARCHAR(5000),
town NVARCHAR(5000),
country_code NVARCHAR(3) -- foreign key
);
Country는 SAP에서 제공하는 sap.common.Countries를 사용함으로써 이미 정의돼 있는 code와 연결된다.
Currency
type Currency : Association to sap.common.Currencies;
Language
type Language : Association to sap.common.Language;
sap.common.Locale
type sap.common.Locale : String(14) @title : '{i18n>LanguageCode}';
'프로그래밍 언어 > CAP' 카테고리의 다른 글
[ CAP ] Views and Projections (2) | 2023.04.12 |
---|---|
[ CAP ] Temporal Database (0) | 2023.04.10 |
[ CAP ] What is the 'CSV'? (0) | 2023.04.04 |
[ CAP ] What is the 'Associations'? (0) | 2023.03.31 |