Versions allow you to manage divergent states of your data, similar to branching in Git. This is a powerful feature for building applications that need to support drafts, experiments, or different contexts for the same data.
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
.
import { openLix } from "@lix-js/sdk";
const activeVersion = await lix.db
.selectFrom("active_version")
.innerJoin("version", "active_version.version_id", "version.id")
.select(["version.id", "version.name"])
.executeTakeFirstOrThrow();
console.log("Current active version:", activeVersion.name);
const newVersion = await createVersion({ lix, from: activeVersion });
console.log("Created new version:", newVersion.name);
await switchVersion({ lix, to: newVersion });
console.log("Switched to new version");
import { openLix } from "@lix-js/sdk";
const activeVersion = await lix.db
.selectFrom("active_version")
.innerJoin("version", "active_version.version_id", "version.id")
.select(["version.id", "version.name"])
.executeTakeFirstOrThrow();
console.log("Current active version:", activeVersion.name);
const newVersion = await createVersion({ lix, from: activeVersion });
console.log("Created new version:", newVersion.name);
await switchVersion({ lix, to: newVersion });
console.log("Switched to new version");
// Switch back to main version for merging demonstration
await switchVersion({ lix, to: activeVersion });
await mergeVersion({ lix, source: newVersion, target: activeVersion });
console.log("Merged feature branch into main");