Function: openLix()

openLix(args: { account?: { id: LixGenerated<string>; name: string; }; blob?: Blob; keyValues?: NewStateAll<LixKeyValue>[]; providePlugins?: LixPlugin[]; storage?: LixStorageAdapter; }): Promise<Lix>

Opens a Lix instance.

Creates an in-memory database by default. If a blob is provided, the database is initialized with that data. If a database is provided, uses that database directly.

Example

// In-memory (default)
const lix = await openLix({})

// From existing data
const lix = await openLix({ blob: existingLixFile })

// With custom storage adapter
import { MyCustomStorage } from "./my-custom-storage.js"
const lix = await openLix({
  storage: new MyCustomStorage()
})

Parameters

ParameterTypeDescription
args{ account?: { id: LixGenerated<string>; name: string; }; blob?: Blob; keyValues?: NewStateAll<LixKeyValue>[]; providePlugins?: LixPlugin[]; storage?: LixStorageAdapter; }-
args.account?{ id: LixGenerated<string>; name: string; }The account that is opening this lix. Lix will automatically set the active account to the provided account. Example const account = localStorage.getItem("account") const lix = await openLix({ account })
args.account.idLixGenerated<string>-
args.account.namestring-
args.blob?BlobLix file data to initialize the database with.
args.keyValues?NewStateAll<LixKeyValue>[]Set the key values when opening the lix. The lixcol_version_id defaults to the active version. Example const lix = await openLix({ keyValues: [{ key: "lix_sync", value: "false" }] })
args.providePlugins?LixPlugin[]Usecase are lix apps that define their own file format, like inlang (unlike a markdown, csv, or json plugin). (+) avoids separating app code from plugin code and resulting bundling logic. (-) such a file format must always be opened with the file format sdk. the file is not portable Example const lix = await openLix({ providePlugins: [myPlugin] })
args.storage?LixStorageAdapterStorage adapter for persisting lix data. Default InMemoryStorage

Returns

Promise<Lix>