Skip to main content

Class SQLiteContext

SQLite implementation of IDatabaseContext for use in Unity. Supports both persistent and in-memory databases depending on the platform.

public class SQLiteContext : IDatabaseContext

Inheritance​

object→SQLiteContext

Implements​

IDatabaseContext

Constructors​

SQLiteContext()​

Initializes a new instance of the SQLiteContext class and establishes a connection to the SQLite database.

public SQLiteContext()

Methods​

Create<T>(T)​

Inserts a new item into the database.

public void Create<T>(T item)

Parameters​

NameTypeDescription
itemTThe item to insert.

Type Parameters​

NameTypeDescription
TThe type of the item to insert.

CreateOrUpdate<T>(T)​

Inserts a new item or updates an existing one in the database.

public void CreateOrUpdate<T>(T item)

Parameters​

NameTypeDescription
itemTThe item to insert or update.

Type Parameters​

NameTypeDescription
TThe type of the item to insert or update.

Delete<T>(T)​

Deletes the specified item from the database.

public void Delete<T>(T item)

Parameters​

NameTypeDescription
itemTThe item to delete.

Type Parameters​

NameTypeDescription
TThe type of the item to delete.

DeleteById<T, K>(K)​

Deletes an item from the database using its primary key.

public void DeleteById<T, K>(K primaryKey)

Parameters​

NameTypeDescription
primaryKeyKThe primary key of the item to delete.

Type Parameters​

NameTypeDescription
TThe type of the item to delete.
KThe type of the primary key.

Read<T>(Expression<Func<T, bool>>)​

Retrieves a single item from the database that matches the specified predicate.

public T Read<T>(Expression<Func<T, bool>> predicate) where T : new()

Parameters​

NameTypeDescription
predicateExpression<Func<T, bool>>An expression used to filter the item.

Returns​

T — The item that matches the predicate, or null if no match is found.

Type Parameters​

NameTypeDescription
TThe type of the item to read.

ReadAll<T>()​

Retrieves all items of the specified type from the database.

public List<T> ReadAll<T>() where T : new()

Returns​

List<T> — A list of all items of the specified type.

Type Parameters​

NameTypeDescription
TThe type of the items to read.

Update<T>(T)​

Updates an existing item in the database.

public void Update<T>(T item)

Parameters​

NameTypeDescription
itemTThe item with updated values.

Type Parameters​

NameTypeDescription
TThe type of the item to update.
  • Constructors
    • SQLiteContext()
  • Methods
    • Create<T>(T)
    • CreateOrUpdate<T>(T)
    • Delete<T>(T)
    • DeleteById<T, K>(K)
    • Read<T>(Expression<Func<T, bool>>)
    • ReadAll<T>()
    • Update<T>(T)