데이터는 트랜잭션 ID 및 컬렉션 ID(또는 Subledger ID)의 두 가지 기본 방법으로 Azure Confidential Ledger 내에서 구성됩니다. 각 쓰기 작업은 항목을 검색하거나, 영수증을 가져오거나, 다른 작업을 수행하는 데 사용할 수 있는 고유한 트랜잭션 ID를 생성합니다. 컬렉션 ID는 항목을 그룹화하거나 고유하게 식별하여 보다 효율적인 데이터 검색 및 관리를 가능하게 하는 사용자 지정 키(선택 사항)입니다. 이 페이지에서는 원장 항목을 만들고, 트랜잭션 ID별로 항목을 검색하고, 범위 또는 컬렉션 내에서 항목을 나열하는 방법을 보여 줍니다.
또한 보조 키 역할을 하여 컬렉션 내에서 데이터 관리를 개선할 수 있는 태그(미리 보기)를 통해 데이터를 구성하고 쿼리할 수 있습니다.
트랜잭션 ID
원장에 기록되는 모든 쓰기는 쓰기 엔드포인트의 응답에 반환되는 트랜잭션 ID를 생성합니다. 다음 예제와 같습니다.
sample_entry = {"contents": "Hello world!"}
append_result = ledger_client.create_ledger_entry(entry=sample_entry)
print(f"Transaction ID: {append_result['transactionId']}")
응답:
Transaction ID: 2.10
응답의 트랜잭션 ID를 사용하여 항목을 검색하거나 영수증 검색 등의 다른 작업을 수행할 수 있습니다. 다음 예제와 비슷한 범위의 트랜잭션 ID 매개 변수를 제공하여 항목 목록을 가져올 수도 있습니다.
# Get the latest transaction to the ledger default/global table
get_result = ledger_client.get_current_ledger_entry()
# Get one transaction
get_result = ledger_client.get_ledger_entry(transaction_id=2.10)
# Get a list of transactions within a range
list_result = ledger_client.list_ledger_entries(from_transaction_id=2.1, to_transaction_id=2.50)
컬렉션 ID
Azure Ledger의 컬렉션 ID(Subledger ID라고도 함)는 원장에 기록된 항목에 대해 사용자가 지정한 선택적 키를 나타냅니다. 나중에 데이터를 검색하는 데 사용할 수 있는 작성 중인 데이터에 키 또는 마커를 추가하는 방법을 제공합니다.
컬렉션 ID는 문자열이며 현재 크기 제한이 없습니다. 즉, 최대 크기는 http 요청 크기 제한에 따라 달라집니다.
원장에 기록된 모든 항목에 대해 고유 키로 사용하거나 항목의 하위 섹션을 그룹화할 수 있습니다.
컬렉션 ID를 지정하지 않으면 데이터가 기본 테이블(subledger-0이라고 함)에 기록됩니다.
컬렉션 ID를 지정하려면 사용자가 쓰기 요청 중에 collectionID 매개 변수를 지정해야 합니다.
sample_entry = {"contents": "Secret recipe ingredients...!"}
append_result = ledger_client.create_ledger_entry(entry=sample_entry, collection_id="icecream-flavors")
그런 다음 읽기 작업 중에 collection ID 및 transaction ID를 지정하거나 list 작업에서 컬렉션 ID만 지정하여 트랜잭션을 검색할 수 있습니다.
# Get the latest transaction in a collection
get_result = ledger_client.get_ledger_entry(collection_id="icecream-flavors")
# Get one specific in a collection
list_result = ledger_client.get_ledger_entry(transaction_id=2.68,collection_id="icecream-flavors")
# Get all entries in a collection
list_result = ledger_client.list_ledger_entries(collection_id="icecream-flavors")
for entry in list_result:
print(f"Transaction ID: {entry['transactionId']}")
print(f"Contents: {entry['contents']}")
컬렉션 ID와 트랜잭션 ID 매개 변수 범위를 모두 지정하여 컬렉션 내의 항목 목록을 가져올 수도 있습니다.
list_result = ledger_client.list_ledger_entries(from_transaction_id=2.1, to_transaction_id=2.50, collection_id="icecream-flavors")
태그(미리 보기)
컬렉션에 태그를 추가하는 것은 원장의 최신 미리 보기 버전에서 사용할 수 있는 미리 보기 기능입니다. 액세스를 위해 REST API 참조 2024-12-09-preview에 기반하거나 최신 버전의 SDK 버전으로 업그레이드합니다.
또한 이 기능은 공개 원장 유형의 기밀 원장으로 제한됩니다. 민간의 원장 유형은 지원되지 않습니다.
이를 통해 데이터 컬렉션의 보조 키 역할을 하여 컬렉션 내의 데이터 관리를 개선할 수 있습니다. 태그는 64자 문자열로 제한됩니다. 각 트랜잭션은 최대 5개의 태그를 지원할 수 있습니다. 지원되는 태그 수와 관련된 오류가 표시되고 더 높은 제한이 필요한 경우 지원에 문의하세요.
컬렉션 내에서 태그를 사용하려면 태그 매개 변수를 지정해야 합니다.
# multiple tags can be specified using commas.
append_result = ledger_client.create_ledger_entry(entry=sample_entry, collection_id="icecream-flavors", tags="chocolate,vanilla")
항목 검색은 이전과 같이 수행할 수 있습니다.
# Get all entries in a collection which has a specified tag. Only one tag is supported per query during a Read operation. Only list/ranged operations are supported with tags.
list_result = ledger_client.list_ledger_entries(collection_id="icecream-flavors", tag="chocolate")
for entry in list_result:
print(f"Transaction ID: {entry['transactionId']}")
print(f"Contents: {entry['contents']}")