Versions enable parallel work, safe experimentation, and clear diffs in Lix. They allow you to create isolated environments for different tasks or experiments, similar to branches in Git.
Parallel work | Multiple AI agents — and human editors — can make different changes at the same time without overwriting each other's progress. |
Risk free experiments | Let agents make changes without impacting the users' version—delete instantly if results disappoint. |
Clear diffs & reviews | See exactly what each agent (or human) changed between versions. |
Let different AI agents create competing advertisements autonomously, then automatically promote the one with better conversion rates.
Key benefits:
Versions in Lix are like branches in Git—they are pointers to a specific commit that expresses state at a point in time.
Lix uses the term "version" instead of "branch" because it's more intuitive for non-technical users. "Version" mirrors the familiar concept of duplicating a file and adding v2
or final
to the file name e.g. something_v2.docx
or something_final.docx
.
Versions let you work with different states of your data in isolation. Here's a simple example showing how to update product prices in a separate version:
import { openLix, createVersion, switchVersion } from "@lix-js/sdk";
import { plugin as jsonPlugin } from "@lix-js/plugin-json";
const lix = await openLix({
providePlugins: [jsonPlugin],
});
// Get main version info for later use
const mainVersion = await lix.db
.selectFrom("version")
.where("name", "=", "main")
.select(["id"])
.executeTakeFirstOrThrow();
// Helper function to log file differences
const logFileDifferences = (allFiles: any[]) => {
allFiles.forEach((file) => {
const data = JSON.parse(new TextDecoder().decode(file.data));
const versionName =
file.lixcol_version_id === mainVersion.id ? "main" : "price-update";
const tshirtPrice = data.items.find(
(item: any) => item.name === "T-Shirt",
).price;
console.log(`T-Shirt price in '${versionName}': $${tshirtPrice}`);
});
};
// Create a product catalog file in the main version
await lix.db
.insertInto("file")
.values({
path: "/products.json",
data: new TextEncoder().encode(
JSON.stringify({
items: [{ id: 1, name: "T-Shirt", price: 29.99, stock: 100 }],
}),
),
})
.execute();
// 1. Create a new version (branches from active version by default)
const priceUpdateVersion = await createVersion({
lix,
name: "price-update",
});
// 2. Switch to the new version
await switchVersion({ lix, to: priceUpdateVersion });
// 3. Modify the file - update prices
await lix.db
.updateTable("file")
.set({
data: new TextEncoder().encode(
JSON.stringify({
items: [{ id: 1, name: "T-Shirt", price: 34.99, stock: 100 }],
}),
),
})
.where("path", "=", "/products.json")
.execute();
// 4. Query files across all versions to see the differences
const allFiles = await lix.db
.selectFrom("file_all")
.where("path", "=", "/products.json")
.select(["lixcol_version_id", "data"])
.execute();
logFileDifferences(allFiles);
Function / Type | Purpose | Docs |
---|---|---|
createVersion() | Create a new version branch | API |
switchVersion() | Change active version | API |
createCheckpoint() | Create a labeled commit | API |
LixVersion | Version type definition | API |