Class DatabaseConnector
Singleton gateway to the SQLite database, providing lazily created typed repositories for each entity type used in the application.
public class DatabaseConnector
Inheritance
Examples
Initialising at startup and using repositories for CRUD operations.
Call Initiailze from the bootstrapper so the connection is ready before any
MonoBehaviour's Awake runs. Call GetRepository` each time you need to
read or write — it is O(1) after the first call because the same repository instance is
returned from the internal dictionary.
// In Bootstrapper.Initiailze() — runs before any scene Awake:
DatabaseConnector.Initiailze();
// Writing a participant record at session start:
var repo = DatabaseConnector.Current.GetRepository();
repo.Write(new ParticipantRecord { Id = 42, Name = "P42" });
// Reading it back by primary key later in the same session:
var record = DatabaseConnector.Current.GetRepository().ReadByID(42);
// Listing all stored records for post-session export:
var all = DatabaseConnector.Current.GetRepository().ReadAll();
Remarks
Opening an SQLite connection is relatively expensive. Holding a single connection for the application's lifetime (via this singleton) avoids repeatedly paying that cost and ensures all repositories share the same connection context.
The GetRepository` method creates repositories lazily so only the entity types actually used in a given session consume resources. The backing store is currently hard-coded to SQLiteContext;
Properties
Current
Gets the singleton instance, creating it on first access if it does not already exist.
public static DatabaseConnector Current { get; }
Property Value
Remarks
The null-coalescing assignment means this property is effectively idempotent.
Prefer Initiailze at application startup to control exactly when the
connection is established, rather than relying on the first Current access.
Methods
GetRepository<T>()
Retrieves (or lazily creates) the repository for the given entity type. Each entity type gets exactly one repository instance for the lifetime of the connector.
public IRepository<T> GetRepository<T>() where T : class, IPrimaryKey<int>, new()
Returns
IRepository<T> — The IRepository for T.
Type Parameters
| Name | Type | Description |
|---|---|---|
T | The entity type. Must be a class with an integer primary key and a default constructor. |
Initiailze()
Initializes the DatabaseConnector singleton instance if not already initialized.
public static void Initiailze()