Fase 6: Visualizzare la cronologia delle revisioni di un documento - Database Amazon Quantum Ledger (Amazon) QLDB

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Fase 6: Visualizzare la cronologia delle revisioni di un documento

Importante

Avviso di fine del supporto: i clienti esistenti potranno utilizzare Amazon QLDB fino alla fine del supporto il 31/07/2025. Per ulteriori dettagli, consulta Migrare un Amazon QLDB Ledger ad Amazon Aurora Postgre. SQL

Dopo aver modificato i dati di immatricolazione di un veicolo nel passaggio precedente, puoi consultare la cronologia di tutti i proprietari registrati e qualsiasi altro campo aggiornato. In questo passaggio, esegui una query sulla cronologia delle revisioni di un documento nella VehicleRegistration tabella del registro. vehicle-registration

Per visualizzare la cronologia delle revisioni
  1. Utilizzate il seguente programma (QueryHistory.ts) per interrogare la cronologia delle revisioni del VehicleRegistration documento con. VIN 1N4AL11D75C109151

    /* * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: MIT-0 * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * software and associated documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import { QldbDriver, Result, TransactionExecutor } from "amazon-qldb-driver-nodejs"; import { dom } from "ion-js"; import { getQldbDriver } from "./ConnectToLedger"; import { VEHICLE_REGISTRATION } from "./model/SampleData"; import { VEHICLE_REGISTRATION_TABLE_NAME } from "./qldb/Constants"; import { prettyPrintResultList } from "./ScanTable"; import { error, log } from "./qldb/LogUtil"; import { getDocumentId } from "./qldb/Util"; /** * Find previous primary owners for the given VIN in a single transaction. * @param txn The {@linkcode TransactionExecutor} for lambda execute. * @param vin The VIN to find previous primary owners for. * @returns Promise which fulfills with void. */ async function previousPrimaryOwners(txn: TransactionExecutor, vin: string): Promise<void> { const documentId: string = await getDocumentId(txn, VEHICLE_REGISTRATION_TABLE_NAME, "VIN", vin); const todaysDate: Date = new Date(); // set todaysDate back one minute to ensure end time is in the past // by the time the request reaches our backend todaysDate.setMinutes(todaysDate.getMinutes() - 1); const threeMonthsAgo: Date = new Date(todaysDate); threeMonthsAgo.setMonth(todaysDate.getMonth() - 3); const query: string = `SELECT data.Owners.PrimaryOwner, metadata.version FROM history ` + `(${VEHICLE_REGISTRATION_TABLE_NAME}, \`${threeMonthsAgo.toISOString()}\`, \`${todaysDate.toISOString()}\`) ` + `AS h WHERE h.metadata.id = ?`; await txn.execute(query, documentId).then((result: Result) => { log(`Querying the 'VehicleRegistration' table's history using VIN: ${vin}.`); const resultList: dom.Value[] = result.getResultList(); prettyPrintResultList(resultList); }); } /** * Query a table's history for a particular set of documents. * @returns Promise which fulfills with void. */ const main = async function(): Promise<void> { try { const qldbDriver: QldbDriver = getQldbDriver(); const vin: string = VEHICLE_REGISTRATION[0].VIN; await qldbDriver.executeLambda(async (txn: TransactionExecutor) => { await previousPrimaryOwners(txn, vin); }); } catch (e) { error(`Unable to query history to find previous owners: ${e}`); } } if (require.main === module) { main(); }
    Nota
    • È possibile visualizzare la cronologia delle revisioni di un documento interrogando la sintassi incorporata Funzione di cronologia nella seguente sintassi.

      SELECT * FROM history( table_name [, `start-time` [, `end-time` ] ] ) AS h [ WHERE h.metadata.id = 'id' ]
    • L'ora di inizio e l'ora di fine sono entrambe opzionali. Sono valori letterali di Amazon Ion che possono essere indicati con backticks (). `...` Per ulteriori informazioni, consulta Interrogare Ion con PartiQL in Amazon QLDB.

    • Come best practice, qualifica una query cronologica con un intervallo di date (ora di inizio e ora di fine) e un ID del documento (). metadata.id QLDBelabora SELECT le interrogazioni nelle transazioni, che sono soggette a un limite di timeout delle transazioni.

      QLDBla cronologia è indicizzata in base all'ID del documento e al momento non è possibile creare indici cronologici aggiuntivi. Le interrogazioni cronologiche che includono l'ora di inizio e l'ora di fine ottengono il vantaggio della qualificazione per intervalli di date.

  2. Per eseguire il programma transpiled, immettete il seguente comando.

    node dist/QueryHistory.js

Per verificare crittograficamente una revisione del documento nel registro, procedi a. vehicle-registration Passaggio 7: Verificare un documento in un libro mastro