Skip to main content
Mastra 1.0 is available 🎉 Read announcement

dataset.getItemHistory()

Added in: @mastra/core@1.4.0

Retrieves the full SCD-2 (Slowly Changing Dimension Type 2) history of a specific item across all dataset versions.

Usage example
Direct link to Usage example

import { Mastra } from "@mastra/core";

const mastra = new Mastra({ /* storage config */ });

const dataset = await mastra.datasets.get({ id: "dataset-id" });

const history = await dataset.getItemHistory({ itemId: "item-id" });

for (const row of history) {
console.log(`Version ${row.datasetVersion}: ${row.isDeleted ? "deleted" : "active"}`);
}

Parameters
Direct link to Parameters

itemId:

string
ID of the item to retrieve history for.

Returns
Direct link to Returns

result:

Promise<DatasetItemRow[]>
Array of versioned item rows, ordered by version.
DatasetItemRow

id:

string
Unique row identifier.

datasetId:

string
ID of the parent dataset.

datasetVersion:

number
Dataset version for this row.

validTo:

number | null
Version at which this row was superseded, or `null` if still current.

isDeleted:

boolean
Whether this row represents a deletion.

input:

unknown
Input data at this version.

groundTruth?:

unknown
Ground truth at this version.

metadata?:

Record<string, unknown>
Metadata at this version.

createdAt:

Date
When this row was created.

updatedAt:

Date
When this row was last updated.
On this page