import { newLixFile, openLix } from "@lix-js/sdk";
import { plugin as jsonPlugin } from "@lix-js/plugin-json";
// Create and open a new Lix file
const lixFile = await newLixFile();
const lix = await openLix({
blob: lixFile,
providePlugins: [jsonPlugin],
});
// Insert a JSON file
const data = {
name: "My Project",
version: "1.0.0",
settings: { theme: "dark", fontSize: 14 }
};
await lix.db
.insertInto("file")
.values({
path: "/config.json",
data: new TextEncoder().encode(JSON.stringify(data)),
})
.execute();
// Make a change
data.version = "1.1.0";
data.settings.fontSize = 16;
await lix.db
.updateTable("file")
.set({
data: new TextEncoder().encode(JSON.stringify(data)),
})
.where("path", "=", "/config.json")
.execute();
// View the changes
const changes = await lix.db
.selectFrom("change")
.innerJoin("file", "file.id", "change.file_id")
.where("file.path", "=", "/config.json")
.selectAll()
.execute();
console.log("Changes:", changes);