For AI agents: the complete documentation index is available at /lite-db/en/llms.txt, the full documentation bundle is available at /lite-db/en/llms-full.txt, and this page is available as Markdown at /lite-db/en/getting-started.md.

Getting Started

This page walks through the minimal flow from installation to your first query.

Installation

In Unity Package Manager, open Add package from git URL... and enter the address below.

https://github.com/achieveonepark/lite-db.git

Dependencies

PackagePurpose
com.cysharp.unitaskAsynchronous DB file copy and initialization
com.unity.test-frameworkUnity test environment

Targets Unity 2022.3 or later.

Preparing the DB file

LiteDB reads a SQLite DB file and maps it to C# models. You can create the DB file with a tool such as DB Browser for SQLite.

The default initialization API uses the following locations.

PurposePath
Source DBApplication.streamingAssetsPath/data/file.db
Runtime copyApplication.persistentDataPath/data/localdatasqlite.db

Place the source DB file at StreamingAssets/data/file.db.

Writing a data model

Write a C# class that corresponds to the table you want to query. Using Id as the primary key is recommended.

using Achieve.Database;
using SQLite;

[Table("Quest")]
public sealed class Quest : IDataBase
{
    [PrimaryKey]
    public int Id { get; set; }
    public string Name { get; set; }
    public int RewardGold { get; set; }
}

Initialization and first query

Call await LiteDB.Initialize() at game start to copy the source DB file to the runtime path and connect. After that, read data with APIs like LiteDB.Get<T>(id).

await LiteDB.Initialize();

var quest = LiteDB.Get<Quest>(1);
if (LiteDB.TryGetValue<Quest>(2, out var nextQuest))
{
    Debug.Log(nextQuest.Name);
}
Info

On Android, StreamingAssets files are read via UnityWebRequest; on other platforms, file copy is used. To specify a path directly, use LiteDB.Initialize(path).

Next steps