logo
  • Docs
  • API Reference
    Introduction
    What is Lix?
    Getting Started
    Comparison to Git
    Lix for AI Agents
    Essentials
    How Lix Works
    Querying Changes
    Data Model
    Plugins
    Persistence
    Guides
    Versions (Branching)
    History
    Diffs
    Attribution (Blame)
    Change Proposals
    Validation Rules
    Undo/Redo
    Restore
    Conversations
    Labels
    Key-Value Store
    Environment API
    Testing
    React Integration
    Logging & Debugging
    Deterministic Mode
    Metadata
    Writer Key
    Architecture
    Lix as File Format
    Previous pageUndo/RedoNext pageConversations

    #Restore

    Restore enables applications to revert to a previous state using any change set ID, providing a powerful safety net for users. This is especially useful when working with AI agents, as it provides a way to recover from unintended changes.

    Restore

    #Examples

    #Restore to the last change set

    import { openLix } from "@lix-js/sdk";
    // Get the most recent change set from the history
    const lastChangeSet = await lix.db
      .selectFrom("change_set")
      .select(["id", "lixcol_metadata"])
      .executeTakeFirstOrThrow();
    
    // Restore the lix to that change set
    await restore({ lix, to: lastChangeSet.id });
    
    console.log("Restored to most recent change set:", lastChangeSet.id);

    #Create and use a checkpoint

    import { openLix } from "@lix-js/sdk";
    
    // Get the most recent change set from the history
    const lastChangeSet = await lix.db
      .selectFrom("change_set")
      .select(["id", "lixcol_metadata"])
      .executeTakeFirstOrThrow();
    
    // Restore the lix to that change set
    await restore({ lix, to: lastChangeSet.id });
    
    console.log("Restored to most recent change set:", lastChangeSet.id);
    // Later, you can easily find and restore to that checkpoint
    const checkpoints = await selectCheckpoints({ lix });
    const results = await checkpoints.execute();
    
    if (results.length > 0) {
      await restore({ lix, to: results[0].id });
      console.log("Restored to checkpoint:", results[0].name);
    } else {
      console.log("No checkpoints available");
    }