logo
  • Docs
  • Plugins
  • API Reference
    Introduction
    What is Lix?
    Getting Started
    Comparison to Git
    Lix for AI Agents
    Release Notes
    Essentials
    Filesystem
    SQL Interface
    Schemas
    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 pageFilesystemNext pageSchemas

    #SQL Interface

    Lix exposes all data through SQL. You can query current state, by version, or full history at the file or entity level.

    #Available Tables

    Lix provides six tables organized by scope and granularity:

    File LevelEntity Level
    Current Statefilestate
    By Versionfile_by_versionstate_by_version
    Historyfile_historystate_history

    See History for details on querying historical data and using *_by_version and *_history tables.

    #Table Schemas

    Use these schema references when building queries. Nullable columns are marked as such; timestamps are ISO strings stored as TEXT in SQLite.

    #state (active version)

    ColumnTypeNotes
    entity_idTEXTEntity identifier unique within a file/schema
    schema_keyTEXTSchema key (matches your x-lix-key)
    file_idTEXTOwning file ID
    plugin_keyTEXTPlugin that owns the entity type
    snapshot_contentJSONCurrent JSON payload
    schema_versionTEXTSchema version string (e.g., 1.0)
    created_atTEXTWhen this version-local state was created
    updated_atTEXTLast update time within the active version
    inherited_from_version_idTEXT, nullableSource version when inherited
    change_idTEXTChange that produced the state
    untrackedINTEGER/BOOLEAN1 for untracked UI/ephemeral state
    commit_idTEXTCommit that contains the change
    writer_keyTEXT, nullableWriter attribution for echo suppression
    metadataJSON, nullableMetadata attached to the originating change

    #state_by_version (all versions)

    ColumnTypeNotes
    entity_idTEXTEntity identifier unique within a file/schema
    schema_keyTEXTSchema key (matches your x-lix-key)
    file_idTEXTOwning file ID
    version_idTEXTVersion that owns this row
    plugin_keyTEXTPlugin that owns the entity type
    snapshot_contentJSONJSON payload for this version
    schema_versionTEXTSchema version string (e.g., 1.0)
    created_atTEXTWhen this version-local state was created
    updated_atTEXTLast update time within this version
    inherited_from_version_idTEXT, nullableSource version when inherited
    change_idTEXTChange that produced the state
    untrackedINTEGER/BOOLEAN1 for untracked UI/ephemeral state
    commit_idTEXTCommit that contains the change
    writer_keyTEXT, nullableWriter attribution for echo suppression
    metadataJSON, nullableMetadata attached to the originating change

    #state_history (read-only history)

    ColumnTypeNotes
    entity_idTEXTEntity identifier unique within a file/schema
    schema_keyTEXTSchema key (matches your x-lix-key)
    file_idTEXTOwning file ID
    plugin_keyTEXTPlugin that owns the entity type
    snapshot_contentJSONHistorical JSON payload at this point
    metadataJSON, nullableMetadata from the change that produced the state
    schema_versionTEXTSchema version string (e.g., 1.0)
    change_idTEXTChange that produced the historical state
    commit_idTEXTCommit where this state was created
    root_commit_idTEXTCommit you are traversing history from
    depthINTEGERDistance from root_commit_id (0 = root)
    version_idTEXTAlways global (history is global across versions)

    #Current State

    Query the current (latest) state of your data.

    #File Level

    // Get all files in the current version
    const files = await lix.db.selectFrom("file").selectAll().execute();
    
    // Get a specific file
    const file = await lix.db
      .selectFrom("file")
      .where("path", "=", "/example.json")
      .selectFirst();

    #Entity Level

    // Get a specific entity (e.g., a JSON property)
    const entity = await lix.db
      .selectFrom("state")
      .where("entity_id", "=", "/example.json/name")
      .selectFirst();

    #State By Version

    Query data at a specific version, useful for comparing versions or accessing data from a different version.

    #File Level

    // Get a file from a specific version
    const file = await lix.db
      .selectFrom("file_by_version")
      .where("path", "=", "/example.json")
      .where(
        "lixcol_root_commit_id",
        "=",
        lix.db
          .selectFrom("version")
          .where("name", "=", "feature-branch")
          .select("commit_id"),
      )
      .selectFirst();

    #Entity Level

    // Get an entity from a specific version
    const entity = await lix.db
      .selectFrom("state_by_version")
      .where("entity_id", "=", "/example.json/name")
      .where(
        "lixcol_root_commit_id",
        "=",
        lix.db
          .selectFrom("version")
          .where("name", "=", "feature-branch")
          .select("commit_id"),
      )
      .selectFirst();

    #History

    Query past states by specifying a starting commit (lixcol_root_commit_id) and traversal depth.

    Common pattern for getting current version's commit:

    const currentCommit = lix.db
      .selectFrom("active_version")
      .innerJoin("version", "active_version.version_id", "version.id")
      .select("version.commit_id");

    #File Level History

    // Query file history from the active version's commit
    const fileHistory = await lix.db
      .selectFrom("file_history")
      .where("path", "=", "/example.json")
      .where("lixcol_root_commit_id", "=", currentCommit)
      .orderBy("lixcol_depth", "asc") // 0 = current, 1 = one back, etc.
      .select(["path", "data", "lixcol_depth"])
      .execute();

    #Entity Level History

    // Get history for a specific entity
    const entityHistory = await lix.db
      .selectFrom("state_history")
      .where("entity_id", "=", "/example.json/name")
      .where("lixcol_root_commit_id", "=", currentCommit)
      .orderBy("lixcol_depth", "asc")
      .selectAll()
      .execute();

    See History for more examples.

    #See Also

    • History - View complete change history
    • Diffs - Compare states across time and versions
    • Versions - Work with branches
    • Attribution - Track who changed what